ID:               47384
 User updated by:  alreece45 at gmail dot com
-Summary:          self and parent aren't using the class where defined
 Reported By:      alreece45 at gmail dot com
 Status:           Open
-Bug Type:         Documentation problem
+Bug Type:         Scripting Engine problem
 Operating System: Linux/Windows
-PHP Version:      Irrelevant
+PHP Version:      PHP5/PHP6
 New Comment:

Perhaps this is not a Documentation Problem, but a scripting problem? I
set it as documentation because I wasn't sure if this behavior was
intentional or not. If it was intentional, the documentation needed to
be updated because it currently says:

"Static references to the current class like self:: or __CLASS__ are
resolved using the class in which the function belongs, as in where it
was defined"

I'd appreciate it to know, at the very least, if this behavior is
intentional or not for two reasons:
1) Avoid using the "feature" in PHP projects.
2) So I know if I take the time to try make a patch: I know I didn't
just waste my time (even if I fail).

also: updating the summary to be more clear (hopefully)


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

[2009-02-13 22:55:01] alreece45 at gmail dot com

Description:
------------
When defining properties using constants with parent or self, they are
resolved using computed classes instead of defined classes.

This behavior appears to have existed since PHP 5.0.5 and still exists
in PHP 5.3beta3, a 5.3 CVS snapshot (200902122000), and 5.2 CVS snapshot
(200902121200).

Someone has brought this up before in php-internals:
http://marc.info/?l=php-internals&m=118839969729862&w=2

Reproduce code:
---------------
<?php
        class Father {
                const my_name = 'Father';
                public $name = self::my_name;
        }
        class Son extends Father {
                const my_name = 'Son';
                public $daddy = parent::my_name;
        }
        class GrandSon extends Son {
                const my_name = 'Grandchild';
        }

        $older = new GrandSon;
        echo "{$older->name}\n";
        echo "{$older->daddy}\n";
?>

Expected result:
----------------
Father
Father

Actual result:
--------------
Grandchild
Son


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


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

Reply via email to