最近我們遷移PHP 5.6到PHP 7是否支持在php 7中引用傳遞?
,現在下面的代碼拋出$this->a =& new test($this->f);
Parse error: syntax error, unexpected 'new' (T_NEW)
什麼想法?我可以用它做什麼改變?
最近我們遷移PHP 5.6到PHP 7是否支持在php 7中引用傳遞?
,現在下面的代碼拋出$this->a =& new test($this->f);
Parse error: syntax error, unexpected 'new' (T_NEW)
什麼想法?我可以用它做什麼改變?
作爲每PHP7不兼容的改變: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
沒有替代。您使用的是不推薦的行爲,現在它不再是有效的PHP。根本不要參照分配。
澄清馬克·B的回答:只是刪除符號這樣
$this->a = new test($this->f);