I'm trying to understand static property behavior in an abstract class.this is an example code retrieved from php object patterns and practice book (chapter 11-decorative pattern) :
abstract class Expression {
private static $keycount=0;
private $key;
function getKey() {
if ( ! isset( $this->key ) ) {
self::$keycount++;
$this->key=self::$keycount;
}
return $this->key;
}
}
a number of sub classes are extended from this abstract class and then getKey()
method will be called at instantiating time.each one check its own $key
property and if its null ,then increase $keycount
by one and assign it to $key
property .
as i understand $keycount
save its last value regardless of which subclass its running on . i mean it is in the context of abstract class NOT the context of sub classes. if it was dependent to its subclass then it would be reset to 0
in each subclass.can anyone provide me more insight into this ?