I have a static function being called that is giving a strange error. Here is an example of the php code:
class foo {
public $stat;
public function __construct() {
$this->stat = stat::isValid('two');
}
}
class stat {
protected static $invalidNumbers = array('one', 'two');
function isValid($number) {
return in_array($number, static::$invalidNumbers);
}
}
$foo = new foo();
var_dump($foo->stat);
This code results in the following error:
Fatal error: Access to undeclared static property: foo::$invalidNumbers
However changing static::
to self::
makes the code behave as expected. I was under the impression that in this context using static::
should work.
Why does this error occur using static
?