gpt4 book ai didi

syntax-error - php 7 支持按引用传递吗?

转载 作者:行者123 更新时间:2023-12-01 07:35:32 24 4
gpt4 key购买 nike

最近我们将 PHP 5.6 迁移到 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 avariable 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 isdeprecated 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.phpon line 3


没有替代。您正在使用已弃用的行为,现在它不再是有效的 PHP。只是不要通过引用分配。

关于syntax-error - php 7 支持按引用传递吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39711137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com