ID: 47384 User updated by: alreece45 at gmail dot com Reported By: alreece45 at gmail dot com Status: Bogus Bug Type: Scripting Engine problem Operating System: Linux/Windows PHP Version: PHP5/PHP6 New Comment:
In the example self is behaving as static does. It should not be doing that. It contradicts the documentation. In the father class: $name is set as self::my_name, which is "Father". In the child classes, even though $name is not set, it goes to Son::my_name and GrandSon::my_name. Previous Comments: ------------------------------------------------------------------------ [2009-06-14 23:09:24] scott...@php.net You can use static:: in PHP 5.3+ this is Late Static Binding. ------------------------------------------------------------------------ [2009-06-14 13:51:01] alreece45 at gmail dot com 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) ------------------------------------------------------------------------ [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