Hi all, If a protected static property is overridden by a public static property, both properties share the same value:
<?php class A { protected static $a; public static function test() { A::$a = 'A::$a'; echo A::$a . "\n"; // Prints 'A::$a' echo B::$a . "\n"; // Also prints 'A::$a', because A::$a and B::$a share values. } } class B extends A { public static $a = 'B::$a'; } A::test(); ?> This behaviour feels strange to me, because: 1. It only applies to that specific combination of visibility modifiers. If you change A::$a to public OR B::$a to protected, then A::$a and B::$a are treated as two separate entities. See pastebin.com/fca2cd5b and pastebin.com/f4f94b32d . 2. It is inconsistent with the behaviour of static methods. See: pastebin.com/f27f009c4 . 3. It differs from the behaviours of C#, Java and C++ (whereas, in most other respects, PHP and these languages share a lot of common ground regarding the concepts of visibility & static-ness). See: http://pastebin.ca/871576, http://pastebin.ca/871975 and http://pastebin.ca/871583. The code for this behaviour was added to zend_compile.c in rev 1.474 (back in sept 2003 :). If I change it to ensure that protected A::$a and public B::$a are treated as separate entities (quick patch against 5.2 snap here: pastebin.com/f7f175924 ), the only tests that fail are those specifically designed to check for this behaviour: Zend/tests/errmsg_024.phpt and ext/reflection/tests/static_properties_002.phpt. Is this a bug? If not, could you help me understand the decision to go with this inheritance rule? Many thanks! Robin -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php