50

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

.

Community
  • 1
  • 1
Sam Smith
  • 617
  • 1
  • 5
  • 6

1 Answers1

90

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) {)

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • Hello, Explosion Pills, - Strangely enough I get more errors if I do such. **Strict Standards: Only variables should be passed by reference** I'm not sure what to do. It's confused me. :\ – Sam Smith Sep 07 '12 at 17:47
  • Hi, Thanks for the post, I am not a PHP person but working on a wordpress theme which showed a error and I fixed using your technique. What is `&$this` I know $this but what happens after `&$this` – localhost Oct 15 '17 at 21:09
  • Unless you are using php 4 which is doubtful you don't need `&$this`. Even if you are using as far back as php 5 you shouldn't need it. It's just an old method for making sure the object self reference `$this` was passed by reference, but since it's already an object reference it's not needed. – Explosion Pills Oct 15 '17 at 21:39