call_user_func(array(&$this, 'method_name'), $args);
I know it mean pass-by-reference when defining functions,but is it when calling a function?
call_user_func(array(&$this, 'method_name'), $args);
I know it mean pass-by-reference when defining functions,but is it when calling a function?
It's pass by reference. Instead of creating a copy to go into the function, it will send the actual variable..
$string = 'test';
hello($string);
function hello(&$s) {
$s .= ' and some more test';
}
// IIRC, the output will be 'test and some more test'
Update
call_user_func(array(&$this, 'method_name'), $args);
I think this code will call a method name within that class, and send $args as parameters. The pass by reference I assume is that it won't attempt to copy the $this, (I'm not sure if it even can). $this would be the reference to the class.
From the Passing By Reference docs page:
You can pass a variable by reference to a function so the function can modify the variable. The syntax is as follows:
<?php
function foo(&$var)
{
$var++;
}
$a=5;
foo($a);
// $a is 6 here
?>
...In recent versions of PHP you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);