php cannot call constructor,ecshop那些事,升级最新版php5.6

是不是对最新版本的php 适配ecshop很苦恼.最近我就遇到了这个事情,最终我花了一个小时的时间把这个问题解决了.

特放出来,方便大家查阅.

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in

\includes\cls_template.php on line 300 的错误,请问我应该怎么改?

这个错误存在于ecshop 最高版本2.7.3 ,在php 5.4 以上版本都存在.

下面我列出需要改动的地方.

用editplus或者其他工具,不建议用记事本,因为可能会改变原有文件的编码格式.

第300行

原有内容:

//return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select('\\1');", $source);

修改后内容:

return preg_replace_callback("/{([^\}\{\n]*)}/", function($r) { return $this->select($r[1]); }, $source);

第491行

原有内容:

//$out

= "<?php \n" . '$k = ' . preg_replace("/(\'\\$[^,]+)/e" ,

"stripslashes(trim('\\1','\''));", var_export($t, true)) . ";\n";

修改后内容:

$out = "<?php \n" . '$k = ' . preg_replace_callback("/(\'\\$[^,]+)/" , function($match){return stripslashes(trim($match[1],'\''));}, var_export($t, true)) . ";\n";

第550行

原有内容:

//$val = preg_replace("/\[([^\[\]]*)\]/eis", "'.'.str_replace('$','\$','\\1')", $val);

修改后内容:

$val = preg_replace_callback('/\[([^\[\]]*)\]/is',function ($matches) {return '.'.str_replace('$','\$',$matches[1]);

},$val);

第1080行

原有内容:

//$source      = preg_replace($pattern, $replacement, $source);

修改后内容:

$source      = preg_replace_callback($pattern, function ($matches) { return '{include file='.strtolower($matches[1]). '}';},

$source);

Only variables should be passed by reference

php 5.3以上版本的问题,应该也和配置有关 只要418行把这一句拆成两句就没有问题了

$tag_sel = array_shift(explode(' ', $tag));

改成:

$tag_arr = explode(' ', $tag); $tag_sel = array_shift($tag_arr);

因为array_shift的参数是引用传递的,5.3以上默认只能传递具体的变量,而不能通过函数返回值。

在后台发现一个错误提示:

Strict Standards: mktime(): You should be using the time() function instead in E:\web\shopex\admin\shop_config.php on line 32

这个错误提示的意思:mktime()方法不带参数被调用时,会被抛出一个报错提示。

找到文件第32行:

$auth = mktime();

将mktime()替换成time()方法,代码为:

$auth = time();

Strict standards: Non-static method cls_sql_dump::get_random_name()

should not be called statically in

D:\wamp\www\yjy_shop\admin\database.php on line 64

这个意思是说非静态方法::cls_sql_dump get_random_name()

既然这样,那我们就好解决了,找到

admin\includes\cls_sql_dump.php 480行

function get_random_name()

{

$str = date('Ymd');

for ($i = 0; $i < 6; $i++)

{

$str .= chr(mt_rand(97, 122));

}

return $str;

}

在前面添加上 static

static function get_random_name()

{

$str = date('Ymd');

for ($i = 0; $i < 6; $i++)

{

$str .= chr(mt_rand(97, 122));

}

return $str;

}

ok,解决

问题一:商城首页报

错 Strict Standards: Only variables should be passed by reference in

D:\wamp\ecshop\includes\cls_template.php on line 422

解决方法:

找到提示错误的文件 cls_template.php 及行号

把$tag_sel = array_shift(explode(' ', $tag));

改成:

$tag_arr = explode(' ', $tag);

$tag_sel = array_shift($tag_arr);

并且删除 D:\wamp\www\ecshop\temp\caches下所有的文件

问题二:后台首页报

错 Strict Standards: Non-static method cls_image::gd_version() should not

be called statically in D:\wamp\www\ecshop\includes\lib_base.php on

line 346

解决办法

找到D:\wamp\www\ecshop\includes\cls_image.php文件

搜索function gd_version改成static function gd_version

问题三:后台-商店设置

Strict Standards: mktime(): You should be using the time() function instead in D:\wamp\www\ecshop\admin\sms_url.php on line 31

Strict Standards: mktime(): You should be using the time()

function instead in D:\wamp\www\ecshop\admin\shop_config.php on line 32

解决办法

根据错误提示 把mktime()改成time()

问题四:后台-起始页

Strict Standards: Redefining already defined c**tructor for class alipay in D:\www\es\includes\modules\payment\alipay.php on line 85

解决办法

1)、错误原因:

PHP 类,有两种构造函数,一种是跟类同名的函数,一种是 __contruct()。从PHP5.4开始,对这两个函数出现的顺序做了最严格的定义,必须是 __c**truct() 在前,同名函数在后

2)、

解决方法:

调换一下两个函数的前后位置即可。

以 includes/modules/payment/alipay.php  为例:

将下面这两个函数的位置互换一下就OK了,__contruct()在前,alipay()在后

function alipay()    {

}

function __contruct()

{

$this->alipay();

}

3)、ECSHOP的很多类文件 都存在这个问题,都需要修改掉。

问题五:后台-数据备份

Strict standards: Redefining already defined

constructor for class cls_sql_dump in

D:\wamp\www\ecshop\admin\includes\cls_sql_dump.php on line 90

Strict standards: Non-static method

cls_sql_dump::get_random_name() should not be called statically in

D:\wamp\www\ecshop\admin\database.php on line 64

解决办法

根据错误提示 把cls_sql_dump的function __construct()改到  function cls_sql_dump()的前面

把cls_sql_dump的function get_random_name()改成 static  function get_random_name()的前面

问题六:

Deprecated: Assigning the return value of new by reference is deprecated in  \admin\sitemap.php on line 46

$sm     =& new google_sitemap();

解决办法

5.3版本之后已经不允许在程序中使用”=&”符号。如果你的网站出现了

Deprecated: Assigning the return value of new by reference is deprecated in 错

误,别着急,先定位到出错的文件,查找下是不是在程序中使用了”=&”,例如刚才定位到网站程序中发现了下图的程序,发现使用了”=&”

符号,去掉‘&’符号之后程序运行正常

问题:Warning: preg_replace_callback(): Modifier /e cannot be used with replacement callback in E:\Program Files\xampps\htdocs\upload\includes\cls_template.php on line 1075

查找:

$pattern     = '/.*?/se';

去掉那个 e !!!

修改为:

$pattern     = '/.*?/s';

错误:Strict standards: Only variables should be passed by reference in \includes\lib_main.php on line 1329

查找:

$ext = end(explode('.', $tmp));

修改为:

$tmp_arr = explode('.', $tmp);

$ext = end($tmp_arr);

array_shift() 的参数是引用传递的,5.3以上默认只能传递具体的变量,而不能通过函数返回值 end(&array) 也一样(后面也会有end的函数,也需要拆分为两行)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值