呼叫时间传递参考已被删除

Sam*_*ith 51 php class function public pass-by-reference

可能重复:
不推荐使用Call-time pass-by-reference

虽然可能会在互联网上的某个地方记录,但我无法找到解决问题的方法.自PHP 5.4更新以来,已删除了pass-by-references.

现在我对这段代码有一个问题,我希望有人可以看到我正在尝试用它做什么,这样他们就可以帮助我找到一个解决方案来克服我的传递引用问题.

以下是有问题的代码:

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;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.

Exp*_*lls 91

仅删除调用时间传递引用.所以改变:

call_user_func($func, &$this, &$client ...
Run Code Online (Sandbox Code Playgroud)

对此:

call_user_func($func, $this, $client ...
Run Code Online (Sandbox Code Playgroud)

&$this 不管怎样,在PHP4之后永远不需要.

如果您绝对需要通过引用传递$ client,请更新函数($ func)签名(function func(&$client) {)