The output is right, it should be 012: http://codepad.org/NVbfDGY7
See this example in the official documentation: http://www.php.net/manual/en/language.variables.scope.php#example-103
<?php
function test()
{
static $a = 0;
echo $a;
$a++;
}
?>
test(); // set $a to 0, print it (0), and increment it, now $a == 1
test(); // print $a (1), and increment it, now $a == 2
test(); // print $a (2), and increment it, now $a == 3
The doc says:
Now, $a is initialized only in first call of function and every time the test() function is called it will print the value of $a and increment it.