ID:               30934
 Comment by:       Jason at amp-design dot net
 Reported By:      jbs at fromru dot com
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: Windows XP Pro SP1
 PHP Version:      5.0.2
 New Comment:

I agree, this is damn annoying. 

However, I'm sure the PHP team will come back saying "Sorry this is not
a bug, it's an undocumented feature". I think this because I remember
reading somewhere the ZE2 deals with constants on compile time, and
therefore any references to self inside a class will point to the the
class name that the reference to self points to. Ideally, if a class is
extended, methods should be checked to see if the parent references
self, and this should then check if the item inside self is referenced
in the current class, or the parent class and adapt accordingly.

It would be so nice if this can be fixed, but I have a nasty felling
people have to live with this :(


Previous Comments:
------------------------------------------------------------------------

[2004-11-29 22:02:49] jbs at fromru dot com

Description:
------------
Special keyword 'self' represents the parent class instead of the child
class when it is used in an inherited method of the parent class.

Reproduce code:
---------------
class Foo {
        const NAME = 'Foo';
        static public function display() {
                echo self::NAME;
        }
        static public function getInstance() {
                $instance = new self;
                return $instance;
        }
}

class Child extends Foo {
        const NAME = 'Child';
}

echo('Class constant: ');
Child::display();
echo('<BR>Object class: ');
echo(get_class(Child::getInstance()));

Expected result:
----------------
Class constant: Child
Object class: Child

Actual result:
--------------
Class constant: Foo
Object class: Foo


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30934&edit=1

Reply via email to