4

Will it be possible to run symfony 1.4 under PHP7?

If yes, which changes have to be done?

Stefan Kraus
  • 53
  • 1
  • 3

2 Answers2

10

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!

Lashae
  • 1,372
  • 1
  • 20
  • 36
B. Walger
  • 119
  • 1
  • 5
8

Check out this question which is related to your problem: Symfony 1.4 using deprecated functions in php 5.5

Depending on your code base I think your best option is to upgrade to Symfony 2 or 3. Or you could use this project which supports 5.6 (maybe 7 in the future?): https://github.com/LExpress/symfony1

Community
  • 1
  • 1
yeouuu
  • 1,863
  • 3
  • 15
  • 32
  • They added PHP 7 support – Michael Noyb Jan 16 '17 at 14:12
  • @MichaelNoyb Can you provide a link? – yeouuu Jan 17 '17 at 22:23
  • 2
    Just visit the repo at https://github.com/LExpress/symfony1 " All the enhancements and BC breaks are listed in the WHATS_NEW file, this include: DIC Composer support PHP 7.0 support performance boost" I switched my already heavily customized 1.4 fork to 1.5.8 (running PHP 5.5) and so far it works pretty well with minimal changes to the existing code. Will upgrade to 7.0 soon to see if any issues pop up – Michael Noyb Jan 19 '17 at 08:30
  • @MichaelNoyb did you guys made any good news on symfony1.4 with php 7 to run. – Rajendra Badri Jun 12 '20 at 05:37
  • 1
    @RajendraBadri indeed we did. The project runs successfully and stable on 7.2. – Michael Noyb Jun 15 '20 at 04:00