PHP 5 and "& new" PHP 5 and "& new" php php

PHP 5 and "& new"


Remove the &.

Objects are passed as reference by default in PHP 5, which is why using the & is deprecated in this context.


So, you've got this or similar error:

Parse error: syntax error, unexpected 'new' (T_NEW) in /usr/share/php/PEAR/Config.php on line 650

Proper fix would be to upgrade all PEAR libraries. But since (as time of writing) there's none, here's how to fix all these errors in PEAR when running PHP 7.

Before the fix.

find /usr/share/php -type f -name \*.php | xargs grep '&new' | wc -l

Returns 77 occurrences.

Now comes sed magic

find /usr/share/php -type f -name \*.php | xargs sed -i 's/&new/new/g'find /usr/share/php -type f -name \*.php | xargs sed -i 's/& new/ new/g'

After the fix

Previous code returns zero occurrences.

You may also want to add this somewhere in PEAR.php:

function set_magic_quotes_runtime() {}