ID: 28442 Updated by: [EMAIL PROTECTED] Reported By: kell_pt at users dot sf dot net -Status: Open +Status: Feedback Bug Type: Zend Engine 2 problem Operating System: * -PHP Version: 5CVS-2004-05-19 (dev) +PHP Version: 5CVS-2004-05-19 New Comment:
Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip Previous Comments: ------------------------------------------------------------------------ [2004-05-22 04:17:45] kell_pt at users dot sf dot net Secondly, there have been more bug reports regarding this issue, or different effects of the model. Anyone having programmed in other enviroments where class inheritance is possible will not feel at home with this, and also it doesn't add anything to the language - it is not only a limitation, but also misleading behaviour. We'd like to see a bit more discussion on this, it *really* isn't a bogus problem. :) Cheers, and I apologize for the insistence, but we're using PHP5 for its new OO features, and it's being hard to cope with the fact that this seems to be overlooked. Hopefully it will be fixed (can't see a reason why it wouldn't). Cheers. ------------------------------------------------------------------------ [2004-05-22 04:13:56] kell_pt at users dot sf dot net It most certainly isn't. Declaring a variable as private static just hides the variable from outside the class. It also allows subclasses to redeclare it. But it doesn't change a thing, and that's not the intended behaviour. An example: class ClassA { private static $cn; public static function setName( $cn ) { self::$cn = $cn; } public static function getName( ) { return self::$cn; } } class ClassB extends ClassA { private static $cn; // with or without this, result is the same } ClassA::setName( 'AAA' ); ClassB::setName( 'BBB' ); print( ClassA::getName() . "\n" ); // prints 'BBB' print( ClassB::getName() . "\n" ); // prints 'BBB' ClassB::setName() is using ClassA as self, when that's not the intended nor propper behaviour. If you call a method on ClassB, it has to affect ClassB, not ClassA - that's how $this works on instances, that's how it should work on static classes. Secondly, ------------------------------------------------------------------------ [2004-05-21 18:12:34] [EMAIL PROTECTED] 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 What you want is \'private static\' ------------------------------------------------------------------------ [2004-05-21 05:28:11] kell_pt at users dot sf dot net I would also like to call your attention to Bug #26930 which was dismissed as "Bogus", where in fact it's a very valid problem. Seems like the behaviour for static data/methods doesn't follow the OO paradigm very close. I hope you guys don't dismiss these problems and provide a sound implementation. :) Cheers. ------------------------------------------------------------------------ [2004-05-19 09:27:20] kell_pt at users dot sf dot net 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 this bug report at http://bugs.php.net/?id=28442&edit=1
