升级PHP7遇到的问题

1、 php7.1.10 把 mcrypt_generic 方法设为 即将遗弃的方法,php7.2将彻底遗弃不再使用,建议使用openssl_encrypt代替。

2、 PHP7 不再支持与类名相同的构造方法,构造方法统一使用 __construct(), 比如下面的写法 PHP7 就会报错误。



3、错误:


原因:
有一个类用了string类名,php7String定为关键字

解决方法:

文件ThinkPHP\Library\Org\Util\Image.class.php

找到

 

import('ORG.Util.String');

$code = String::rand_string($length, 4);

 

修改成

 

import('ORG.Util.Stringnew');

$code = StringNew::rand_string($length, 4);

 

复制文件

ThinkPHP\Library\Org\Util\String.class.php

保存成

ThinkPHP\Library\Org\Util\StringNew.class.php

打开StringNew.class.php

 

class String {

 

修改成

 

class StringNew {


4、如果定义的方法没有给默认值,这时如果不传值,则报错:




5、 初始化变量时,如果给变量设为字符串,但是后面要转换为数组时,则报错:


6、php7,preg_replace()不再支持"\e" (PREG_REPLACE_EVAL),需要使用preg_replace_callback()来代替。

$content = preg_replace("/{#(.+?)}/eis", '$lang[\'\\1\']',$content) ;

这是原来的代码,在php7里不能被正确执行。

 

$content = preg_replace_callback("/{#(.+?)}/is",function($r)use($lang){ return $lang[$r[1]]; }, $content);

7、//  $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];  //接受post数据,PHP7废弃的全局变量

           if(!$postStr){

              $postStr = file_get_contents('php://input');

              }



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值