#30235 [Opn->Bgs]: Inheritance of private static variables fails (related to self:: )
| From: | helly@php.net | Date: | Sun, 26 Sep 2004 18:34:26 +0000 |
| Subject: | #30235 [Opn->Bgs]: Inheritance of private static variables fails (related to self:: ) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-66720@lists.php.net to get a copy of this message | ||
ID: 30235
Updated by: helly@php.net
Reported By: kell_pt at users dot sf dot net
-Status: Open
+Status: Bogus
Bug Type: Zend Engine 2 problem
Operating System: Any
PHP Version: 5CVS-2004-09-25 (dev)
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Sorry, you have a complete wrong idea og OO programming.
Static methods are bound/resolved at compile time. That is the compiler
can replace self with the current class.
Previous Comments:
------------------------------------------------------------------------
[2004-09-25 23:45:00] kell_pt at users dot sf dot net
Description:
------------
The issue is pretty simple I've explained this problem before, I'm
unsure why it hasn't been addressed - it's a design flaw and violates
basic principles of what you'd expect from an OOP language.
Consider a static function in a base class, and a class that inherits
from the above. In such a static function, self:: always refers to the
class where the code was declared. That is wrong, it should be relative
to the class the code was called from. It makes it impossible to have
seperate variables in sub-classes sharing the same code.
It is easier watching the example, it speaks for itself. When "test()"
runs, on the second call, it should be running within context of
ClassB, not ClassA.
This is related to bug #28442, which was apparently ignored. Can
someone at least explain what is the reasoning behind it working like
that? I don't want to sound rude, but I know how it works, the
distinctions between public and private, please don't patronize me
(again). :)
Reproduce code:
---------------
class ClassA
{
private static $base = "Variable from ClassA";
static function test()
{
print( self::$base . "\n" );
}
}
class ClassB extends ClassA
{
private static $base = "Variable from ClassB";
}
ClassA::test();
ClassB::test();
Expected result:
----------------
Variable from ClassA
Variable from ClassB
Actual result:
--------------
Variable from ClassA
Variable from ClassA
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30235&edit=1