The scope of a static variable of a member function

If I have a static variable declared inside a (non-static) member function of a class, is it static for every instance of this class or static in all instances? Sorry if the answer should be obvious, I can't find anything.

EDIT:

I accepted the answer by zerkms, 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

+3
source share
1 answer
  • It will take a few minutes to verify.
  • It is available for all instances.

http://ideone.com/Cq2s6

+6
source

All Articles