2016-09-26 104 views
1

最近我们迁移PHP 5.6到PHP 7是否支持在php 7中引用传递?

,现在下面的代码抛出$this->a =& new test($this->f);

Parse error: syntax error, unexpected 'new' (T_NEW) 

什么想法?我可以用它做什么改变?

回答

5

作为每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。根本不要参照分配。

0

澄清马克·B的回答:只是删除符号这样

$this->a = new test($this->f);