This is my setting:
display_startup_errors = on
display_errors = On
error_reporting = E_ALL | E_STRICT
$b;
function func ($name) {
global $b;
$b = 10;
return $b;
}
$a =& func("myname");
++$a ;
echo '<br/>$a= '.$a.' $b= ' .$b."<br/>";
xdebug_debug_zval('a'); echo "<br/> ";
The above code output's the following notice:
Strict standards: Only variables should be assigned by reference in /path/to/file/file.php on line 'some line number'
$a= 11 $b= 10
a: (refcount=1, is_ref=0)=11
Why is the above code displaying the notice? And why is there a C.O.W (copy on write) taking place?
$b;
function &func ($name) {//change here: to return a reference.
global $b;
$b = 10;
return $b;
}
$a =& func("myname");
++$a ;
echo '<br/>$a= '.$a.' $b= ' .$b."<br/>";
xdebug_debug_zval('a'); echo "<br/> ";
The above code will output:
$a= 11 $b= 11
a: (refcount=1, is_ref=1)=11
Why is no strict standards notice thrown here? And here the reference works.
$b;
function &func ($name) {
global $b;
$b = 10;
return $b;
}
$a = func("myname"); //change here: removed &
++$a ;
echo '<br/>$a= '.$a.' $b= ' .$b."<br/>";
xdebug_debug_zval('a'); echo "<br/> ";
The above code will output:
$a= 11 $b= 10
a: (refcount=1, is_ref=0)=11
Why does a C.O.W take place here?
For info on xdebug_debug_zval visit here.