Call-time pass-by-reference has been removed [duplicate]

試著忘記壹切 提交于 2019-11-26 22:55:24

问题


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.

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;
            }
        }
    }
}

.


回答1:


Only call time pass-by-reference is removed. So change:

call_user_func($func, &$this, &$client ...

To this:

call_user_func($func, $this, $client ...

&$this should never be needed after PHP4 anyway period.

If you absolutely need $client to be passed by reference, update the function ($func) signature instead (function func(&$client) {)



来源:https://stackoverflow.com/questions/12322811/call-time-pass-by-reference-has-been-removed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!