小智 9
对于那些想要使用 symfony 1.4 和 PHP7 的学说 1.2 的人!
在 %SF_LIB_DIR%/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Collection.php 第 463 行你会发现:
$record->$relation['alias'] = $this->reference;
Run Code Online (Sandbox Code Playgroud)
在 PHP 5 中,这被解释为
$record->${relation['alias']} = $this->reference;
Run Code Online (Sandbox Code Playgroud)
作者的意图。在 PHP7 中,它将被解释为
${record->$relation}['alias'] = $this->reference;
Run Code Online (Sandbox Code Playgroud)
导致关系错误的原因。
为了解决这个问题,只需使隐式显式:
$record->{$relation['alias']} = $this->reference;
Run Code Online (Sandbox Code Playgroud)
这个问题就没有了。
此外,您必须更改以下 Doctrine 文件:Doctrine/Adapter/Statement/Oracle.php line 586 from
$query = preg_replace("/(\?)/e", '":oci_b_var_". $bind_index++' , $query);
Run Code Online (Sandbox Code Playgroud)
到
$query = preg_replace_callback("/(\?)/", function () use (&$bind_index) { return ":oci_b_var_".$bind_index++; }, $query);
Run Code Online (Sandbox Code Playgroud)
Doctrine/Connection/Mssql.php 第 264 行来自
$tokens[$i] = trim(preg_replace('/##(\d+)##/e', "\$chunks[\\1]", $tokens[$i]));
Run Code Online (Sandbox Code Playgroud)
到
$tokens[$i] = trim(preg_replace_callback('/##(\d+)##/',function ($m) use($chunks) { return $chunks[(int) $m[1]]; }, $tokens[$i] ));
Run Code Online (Sandbox Code Playgroud)
和第 415 行来自
$query = preg_replace('/##(\d+)##/e', $replacement, $query);
Run Code Online (Sandbox Code Playgroud)
到
$query = preg_replace_callback('/##(\d+)##/', function($m) use ($value) { return is_null($value) ? 'NULL' : $this->quote($params[(int) $m[1]]); }, $query);
Run Code Online (Sandbox Code Playgroud)
PHP7 没有 preg 修饰符 'e' 了。通过这些修改,doctrine 1.2 将继续与 PHP7 一起工作,并且也将与 PHP5 一起工作!
检查出与您的问题有关的问题: Symfony 1.4在PHP 5.5中使用了不推荐使用的函数
根据您的代码库,我认为最好的选择是升级到Symfony 2或3。或者您可以使用支持5.6(将来可能是7)的项目:https : //github.com/LExpress/symfony1