Scope of static variable of member function

instance, member-functions, php, scope, static-variables

Solution

- It would take a couple of minutes to check

- It is shared across all instances

http://ideone.com/Cq2s6

Problem

If I have a static variable declared within a (non-static) member function of a class, is it static to each instance of that class, or static across all instances? Sorry if the answer should be obvious, I can't find it anywhere. EDIT: I have accepted zerkms's answer, but here is another example: ``` <?php class X { public function fun($bar) { static $foo = null; if ($foo != null) print $foo . "<br/>"; $foo = $bar; } } $x1 = new X(); $x1->fun(42); $x2 = new X(); $x2->fun(123); $x2->fun(666); ?> ``` Output: 42 123

Original source