From:             matti at nitro dot fi
Operating system: *
PHP version:      5.1.6
PHP Bug Type:     Scripting Engine problem
Bug description:  Changing a static variables in a class changes it across 
sub/super classes.

Description:
------------
Bug is still open in release versions. When it will be fixed?

http://bugs.php.net/bug.php?id=28442


quote------------


[19 May 2004 9:27am UTC] kell_pt at users dot sf dot net
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:
---------------
quote------------


[19 May 2004 9:27am UTC] kell_pt at users dot sf dot net

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=39044&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39044&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39044&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39044&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39044&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39044&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39044&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39044&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39044&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39044&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39044&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39044&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39044&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39044&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39044&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39044&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39044&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39044&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39044&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39044&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39044&r=mysqlcfg

Reply via email to