Re: Bug with static property access

From: Date: Tue, 04 Oct 2011 18:33:35 +0000
Subject: Re: Bug with static property access
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-55699@lists.php.net to get a copy of this message
On 2011-10-03, Chris Stockton <chrisstocktonaz@gmail.com> wrote: > Hello, > > I noticed the following odd behavior earlier today, there is > definitely a bug here in my opinion, the bug is either the error > message or the behavior. I think the behavior is possibly expected. > I'll let some others comment. > > The reason I think the error is odd is because it is very misleading > in a much larger code base (what I was debugging) you go to the line > it is complaining about and are perplexed because you are not > attempting to access the mentioned constant. I'm sure the engine does > some kind of lazy/runtime determination that causes this, that area > may need a look at? > > Example: ><?php > abstract class ClassA { > static protected $_cache = Array(); > > public $version = self::VERSION; > > final static public function MethodOne() { > return __METHOD__; > } > > final static public function MethodTwo() { > self::$_cache; > return __METHOD__; > } > } > > abstract class ClassB extends ClassA { > const VERSION = 1; > } > > var_dump(ClassB::MethodOne()); > var_dump(ClassB::MethodTwo()); > > ?> > > // prints > string(17) "ClassA::MethodOne" > Fatal error: Undefined class constant 'self::VERSION' in ><SNIP>/testbug.php on line 14 That makes complete sense to me -- ClassA is referring to self, which resolves to ClassA... which does not define a "VERSION" constant. Change to this: public $version = static::VERSION; and it should be fine. -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

« previous php.internals (#55699) next »