ThinkPHP3.1迁移到PHP7的注意事项

阅读前请先移步http://blog.csdn.net/lankecms/article/details/78090678,文本是做相应的补充。

最近项目从PHP5.5升级到了PHP7.0,框架是ThinkPHP3.1.3,记录下升级过程。

一、我用的apache服务器,项目里开启了路由功能,所以.htaccess文件就改成了

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
</IfModule>
二、在PHP7中,preg_replace不能用/e修饰符,所以用preg_replace_callback代替preg_replace,
需要修改的文件包括
ThinkPHP\Lib\Template\ThinkTemplate.class.php
ThinkPHP\Lib\Core\Dispatcher.class.php
ThinkPHP\Lib\Core\Db.class.php
ThinkPHP\Lib\Behavior\CheckRouteBehavior.class.php
ThinkPHP\Extend\Mode\Lite\Dispatcher.class.php


1)ThinkPHP\Lib\Template\ThinkTemplate.class.php
这个文件大约需要修改8处地方
NO1. 大约在137行,将

$tmplContent =  preg_replace('/<!--###literal(\d+)###-->/eis',"\$this->restoreLiteral('\\1')",$tmplContent);
替换为
$tmplContent = preg_replace_callback('/<!--###literal(\d+)###-->/is', function($r) {
	return $this->restoreLiteral($r[1]);
}, $tmplContent);

NO2. 大约在168行,将
$content = preg_replace('/'.$begin.'literal'.$end.'(.*?)'.$begin.'\/literal'.$end.'/eis',"\$this->parseLiteral('\\1')",$content);
替换为
$content = preg_replace_callback('/' . $begin . 'literal' . $end . '(.*?)' . $begin . '\/literal' . $end . '/is', function($r) {
	return $this->parseLiteral($r[1]);
}, $content);

NO3. 大约在197行,将
$content = preg_replace('/('.$this->config['tmpl_begin'].')([^\d\s'.$this->config['tmpl_begin'].$this->config['tmpl_end'].'].+?)('.$this->config['tmpl_end'].')/eis',"\$this->parseTag('\\2')",$content);
替换为
$content = preg_replace_callback('/(' . $this->config['tmpl_begin'] . ')([^\d\s' . $this-&g
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值