Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55699 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16528 invoked from network); 4 Oct 2011 18:33:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Oct 2011 18:33:36 -0000 X-Host-Fingerprint: 96.2.18.191 host-191-18-2-96.midco.net Date: Tue, 04 Oct 2011 14:33:35 -0400 Received: from [96.2.18.191] ([96.2.18.191:25129] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/97-59399-F715B8E4 for ; Tue, 04 Oct 2011 14:33:35 -0400 Message-ID: To: internals@lists.php.net References: User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 96.2.18.191 Subject: Re: Bug with static property access From: weierophinney@php.net (Matthew Weier O'Phinney) On 2011-10-03, Chris Stockton 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: > 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 >/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