Hi Drew. I know about the reference staying in place, but what was fooling me in my example was the second assignment to $foo without the ampersand. It looks like it shouldn't work, you're not assigning by reference the 2nd time, so how does a change of $foo change $y - this now explains it and puts the beast to sleep in my head, it was nothing to do with reference counting or anything that I tried explaining it with, essentially a 'trick of the light'.
<?php
function &gooGoo($returnString = 0)
{
static $yStatic = 'Y Static Initial val';
echo "gooGoo Y: $yStatic <br>";
if ($returnString)
{
echo ' you want string, you get string<br />';
$yStatic = 'change by string condition';
return 'Hi, I am returned string';
}
else
return $yStatic;
}
$proxy = &gooGoo(); // get a control reference to $yStatic
$foo = &gooGoo(); // $foo a definite reference to $yStatic
$foo = 'Change one'; // so $yStatic = 'Change one';
$foo = gooGoo(1);
/* Above I now know $foo equals 'Hi, I am a returned string'
and I assume $yStatic now to be 'change by string condition'
but check it out and it's NOT.
$foo = gooGoo(1) the 2nd time essentially behaves as
$yStatic = 'Hi, I am a returned string' because
$foo IS $yStatic - the eye is just fooled by $foo = gooGoo(1);
*/
echo "\$foo = $foo<br />";
echo '\$proxy = ', $proxy, '<br />';
$foo = 'Second change'; // surely no change - but there IS [though now understood]
$baz = gooGoo();
$baz = 'Third go'; // don't expect change - and there isn't, and never was
gooGoo();
?>