阅读前请先移步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