A static variable is similar to a static member. One minor difference is that it's scoped to the function you've declared it in.
Keep in mind that static members have one other property: they are shared over all instances of a class. Sample code:
class A {
function foo () {
static $a = 0;
$a += 1;
var_dump($a);
}
function bar() {
self::$a; // Fatal error: Access to undeclared static property: A::$a
}
}
$a = new A();
$a->foo(); // 1
$a->foo(); // 2
$a2 = new A();
$a2->foo(); // 3!
This is problematic. My recommendation is: don't use static variables. Just have a private non-static member:
class A {
private $a = 0;
function foo () {
$this->a += 1;
var_dump($this->a);
}
}
$a = new A();
$a->foo(); // 1
$a->foo(); // 2
$a2 = new A();
$a2->foo(); // 1
If you need to cache a value make that it's own entity:
$cache = new ValueProvider();
$a = new A($cache);
$a2 = new A($cache);
Now A doesn't need to know how ValueProvider get's the value, or even that it's cached. $a and $a2 share their ValueProvider, but they don't know about that, and that's good.