Problem accessing static objects via self::
| From: | Jay Smith | Date: | Mon, 15 Sep 2003 14:32:29 +0000 |
| Subject: | Problem accessing static objects via self:: | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-4490@lists.php.net to get a copy of this message | ||
Maybe I'm doing something wrong, but I have some code similar to this...
<?php
class a {
function printme() {
return 'hello world';
}
}
class foo {
protected static $blort = null;
function __construct() {
if (self::$blort == null)
self::$blort = new a;
}
}
class bar extends foo {
function __construct() {
parent::__construct();
var_dump(self::$blort);
var_dump(self::$blort->printme());
}
}
$b = new bar;
?>
Which gives me:
NULL
Fatal error: Call to a member function printme() on a non-object in
/home/jay/static.php on line 22
Seems that the static property $blort in foo is getting lost somewhere.
Meanwhile, accessing $blort in the parent class via parent::$blort gives a
"Cannot access protected property" error.
Am I doing something wrong here, expecting the wrong behaviour, or is this a
bug?
J