Recently we migrated PHP 5.6 to PHP 7
and now following code throws $this->a =& new test($this->f);
Parse error: syntax error, unexpected 'new' (T_NEW)
any ideas? what are the alternation that I could use for it?
To clarify Marc B's answer: just remove the ampersand like this
$this->a = new test($this->f);
As per the PHP7 incompatible changes: http://php.net/manual/en/migration70.incompatible.php
New objects cannot be assigned by reference
The result of the new statement can no longer be assigned to a variable by reference:
<?php class C {} $c =& new C; ?>
Output of the above example in PHP 5:
Deprecated: Assigning the return value of new by reference is deprecated in /tmp/test.php on line 3
Output of the above example in PHP 7:
Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php on line 3
There is no alternative. You were using deprecated behavior, and now it's no longer valid PHP. Simply don't assign by reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With