$v in foo() is an alias for a Basic object.
At the end of foo(), this object goes out of scope, so $v goes out of scope - $v may be static, but what it is an alias of no longer exists, so it no longer exists and is reset on the next call to foo().
$v in bar() is a copy of a Basic object.
At the end of foo(), this object goes out of scope - but since $v is static, it retains the copy for the next call to bar().
This might demonstrate it more simply:
function baz() {
static $a = 0;
$b = 1;
if ($a == 0) {
$a = $b;
echo "hi";
} else {
echo $a;
}
}
baz();
baz();
baz();
We expect hi11 as the answer, since on the first call to baz(), $a is indeed 0, so the value of $b is copied to $a and "hi" is printed.
$a retains this value (i.e. 1) on the next call to baz(), so ($a == 0) is now false, hence the value of $a is printed.
Nothing really changes on the next call to baz(), so we get 11 as the output.
Let's change $a = $b; to $a =& $b;
On the first call to baz(), $a is 0, so $a is set as another name for $b (i.e. $a becomes an alias for $b).
But when baz() returns to the caller, $b goes out of scope.
So on the next call to baz(), $a is reset to 0, and we rinse, wash and repeat this for the next call to baz().
So we expect "hihihi" as the output, and in PHP 5.0.4 this is what I get.