On 2011-10-03, Chris Stockton <[email protected]> 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 | [email protected]
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php