PHP7部署TP3.1系统遇到的问题

一、系统页面访问空白不报错
系统访问之后页面显示空白,但是没有任何的错误提示。

最开始我的第一反应就是模板解析的问题,但是却不知道如何解决,于是网上找了一下解决方案,发现的确存在这个问题。

关键点:preg_replace函数在 PHP7 是彻底废除了,而 PHP5+ 却还能用

存在这个函数的地方主要是三个文件,分别是:

Think\Lib\Template\ThinkTemplate.class.php
ThinkPHP\Lib\Core\Dispatcher.class.php
因此需要将这个函数使用 preg_replace_callback 替换掉。

ThinkPHP 论坛有人提出过解决方案,但是他的解决办法存在问题,会报错误,因此我保存了两个没问题的代码:

1、ThinkTemplate.class.php
代码地址:

https://gitee.com/postbird/codes/7h62mzisqg4t1p5axfkbn44
2、Dispatcher.class.php
代码地址:

https://gitee.com/postbird/codes/3yb4n0sthxc8ipaj9eqor70
用上面的代码把项目文件覆盖掉即可。

二、验证码 Cannot use ‘String’ as class name as it is reserved
在使用验证码的时候,报错如下:

Cannot use ‘String’ as class name as it is reserved

因为 PHP7 把 String 定位关键字,因此报错。

有人给出了解决方案,原文地址:

https://www.phpsong.com/2260.html
总结如下:

1、在 ThinkPHP\Library\Org\Util\ 创建新文件:Stringnew.class.php
该文件内容和同目录下 String.class.php 内容是一样的,只不过将 class String 改为 class Stringnew 而已,如果不想自己改,我也上传了一份改好的代码:

https://gitee.com/postbird/codes/3fswbey27qcdphx9rivt079
2、修改 ThinkPHP\Library\Org\Util\Image.class.php
将下面代码:

import(‘ORG.Util.String’);
c o d e = S t r i n g : : r a n d s t r i n g ( code = String::rand_string( code=String::randstring(length, 4);
修改成:

import(‘ORG.Util.Stringnew’);
c o d e = S t r i n g n e w : : r a n d s t r i n g ( code = Stringnew::rand_string( code=Stringnew::randstring(length, 4);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值