From: kell_pt at users dot sf dot net
Operating system: any
PHP version: 5CVS-2004-05-19 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: Changing a static variables in a class changes it across sub/super
classes.
Description:
------------
It isn't possible to override static variable values in classes, seeing as
the same variable is shared across the whole hierarchy of classes. Each
child class should be able to have their own value for a static variable.
A good example is trying to have a counter of the number of instances per
class.
ClassB::$count will always be the same as ClassA::$count.
It is possible that you don't consider this a bug, but it is quite against
the OOP paradigm, and worth a note. Basically, when loading a subclass,
the default values for the variables should be loaded, and a new variable
(memory space) created, instead of keeping a reference to the superclass'
static variable.
This is somehow related to Bug #16245 (which regards static variables
declared within functions). But where the behaviour in such a situation is
a bit unspecified, in this case it's quite against OO programming.
Reproduce code:
---------------
class ClassA
{
static $count;
static $somevar;
static __construct()
{
self::$count++; // this won't work as expected
}
}
class ClassB extends ClassA
{
}
// another simpler example
ClassA::$somevar = 'A';
ClassB::$somevar = 'B';
// ClassA::$somevar is now 'B' instead of 'A';
ClassA::$somevar = 'A';
// ClassB::$somevar is now 'A' instead of 'B';
--
Edit bug report at http://bugs.php.net/?id=28442&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28442&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28442&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28442&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28442&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28442&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28442&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28442&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28442&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28442&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28442&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28442&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28442&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28442&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28442&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28442&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28442&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28442&r=float