php 调用时传递引用已被删除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12322811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call-time pass-by-reference has been removed
提问by Sam Smith
Possible Duplicate:
Call-time pass-by-reference has been deprecated
可能重复:
调用时传递引用已被弃用
While it may be documented somewhere on the internet, I cannot find a solution to my problem. Since the PHP 5.4 update, pass-by-references have been removed.
虽然它可能在互联网上的某处记录,但我找不到解决我的问题的方法。自 PHP 5.4 更新以来,传递引用已被删除。
Now I have a problem with this section of code, and I hope somebody can see what I'm trying to do with it so that they can possibly help me with a solution to overcome my pass-by-reference problem.
现在这部分代码有问题,我希望有人能看到我想用它做什么,以便他们可以帮助我找到解决我的传递引用问题的解决方案。
Below is the code in question:
下面是有问题的代码:
public function trigger_hooks( $command, &$client, $input ) {
if( isset( $this->hooks[$command] ) ) {
foreach( $this->hooks[$command] as $func ) {
PS3socket::debug( 'Triggering Hook \'' . $func . '\' for \'' . $command . '\'' );
$continue = call_user_func( $func, &$this, &$client, $input );
if( $continue === FALSE ) {
break;
}
}
}
}
.
.
回答by Explosion Pills
Only call timepass-by-reference is removed. So change:
仅删除调用时间传递引用。所以改变:
call_user_func($func, &$this, &$client ...
To this:
对此:
call_user_func($func, $this, $client ...
&$thisshould never be needed after PHP4 anyway period.
&$this无论如何,在 PHP4 之后都不应该需要。
If you absolutely need $client to be passed by reference, update the function ($func) signature instead (function func(&$client) {)
如果您绝对需要通过引用传递 $client,请更新函数 ($func) 签名而不是 ( function func(&$client) {)

