Re: getInstance and new self()

From: Date: Sun, 14 Mar 2004 17:31:33 +0000
Subject: Re: getInstance and new self()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-8513@lists.php.net to get a copy of this message
self:: is always evaluated at compile-time and refers to the class it is defined in and not the concrete object/class. Andi At 05:03 PM 3/8/2004 -0700, Jeffrey Moss wrote:
I found this on a zend engine 2 list archive, but didn't see an answer, has it been resolved? I am trying to create a singleton class heirarchy without having to override getInstance.... <?php class Test {
    public static function getInstance() {
      return new self();
    }
} class Foo extends Test { } var_dump(Foo::getInstance()); ?> thekid@friebes:~/devel/php/tests > php5 self.php object(test)#1 (0) { } Expected output would be "object(foo)", so I guess either "self" should not be evaluated at compile time or this should be disallowed. I'd prefer the first:) http://www.zend.com/lists/engine2/200307/msg00033.html -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.internals (#8513) next »