WIll it be possible to run symfony 1.4 under PHP7?

Stefan Kraus picture Stefan Kraus · Dec 18, 2015 · Viewed 7.5k times · Source

Will it be possible to run symfony 1.4 under PHP7?

If yes, which changes have to be done?

Answer

B. Walger picture B. Walger · Aug 25, 2017

For those, who want to use doctrine 1.2 with symfony 1.4 and PHP7!

In %SF_LIB_DIR%/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Collection.php line 463 you will find:

$record->$relation['alias'] = $this->reference;

In PHP 5 this was interpreted as

$record->${relation['alias']} = $this->reference;

what the author intended. In PHP7 it will be interpreted as

${record->$relation}['alias'] = $this->reference;

what leads to the error regarding relations.

To remedy this problem, just make the implicit explicit:

$record->{$relation['alias']} = $this->reference;

and this problem is gone.

Additionally you have to change in following Doctrine files: Doctrine/Adapter/Statement/Oracle.php line 586 from

$query = preg_replace("/(\?)/e", '":oci_b_var_". $bind_index++' , $query);

to

$query = preg_replace_callback("/(\?)/", function () use (&$bind_index) { return ":oci_b_var_".$bind_index++; }, $query);

Doctrine/Connection/Mssql.php line 264 from

$tokens[$i] = trim(preg_replace('/##(\d+)##/e', "\$chunks[\\1]", $tokens[$i]));

to

$tokens[$i] = trim(preg_replace_callback('/##(\d+)##/',function ($m) use($chunks) { return $chunks[(int) $m[1]]; }, $tokens[$i] ));

and line 415 from

$query = preg_replace('/##(\d+)##/e', $replacement, $query);

to

$query = preg_replace_callback('/##(\d+)##/', function($m) use ($value) { return is_null($value) ? 'NULL' : $this->quote($params[(int) $m[1]]); }, $query);

for PHP7 has no preg modifier 'e' anymore. With those modifications, doctrine 1.2 will continue to work with PHP7 and is working with PHP5 too!