I have two functions
function c( &$x )
{
$x = 25;
echo 'c is called, x = ' . $x . PHP_EOL;
}
function b()
{
echo 'b is called'. PHP_EOL;
return 5;
}
Then I write the following code which as I expect should put result of b() to $o, then pass $o by reference to c() where it is set to the new value. it works ok:
$o=b();
c( $o );
echo 'o is '.$o;
the output is as expected:
b is called c is called, x = 25 o is 25
But if I try to assign value of $o in function call like this:
c( $o = b() );
echo 'o is '.$o;
I get weird output
b is called c is called, x = 25 o is 5
the order of function calls is still the same but why $o is not changed in spite of it was passed by reference? Does PHP compulsorily passes argument by value if it is assigned in function call? If yes, since what version had this been working that way? According to this comment: http://www.php.net/manual/en/functions.arguments.php#71198 in 2006 it worked differently. My version is 5.3.6