From: kell_pt at users dot sf dot net
Operating system: Any
PHP version: 5CVS-2004-09-25 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: Inheritance of private static variables fails (related to self:: )
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 bug report at http://bugs.php.net/?id=30235&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=30235&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30235&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30235&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=30235&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=30235&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=30235&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=30235&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=30235&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=30235&r=support
Expected behavior: http://bugs.php.net/fix.php?id=30235&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=30235&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=30235&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=30235&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=30235&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=30235&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=30235&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=30235&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=30235&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=30235&r=mysqlcfg