Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34965 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16130 invoked by uid 1010); 28 Jan 2008 16:49:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 16115 invoked from network); 28 Jan 2008 16:49:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2008 16:49:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:57954] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/62-26775-E770E974 for ; Mon, 28 Jan 2008 11:49:04 -0500 Received: from dhcp-172-28-202-237.zrh.corp.google.com (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 705101B3524; Mon, 28 Jan 2008 17:48:59 +0100 (CET) Date: Mon, 28 Jan 2008 17:49:26 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <868592137.20080128174926@marcus-boerger.de> To: "Robin Fernandes" CC: "Marcus Boerger" , internals@lists.php.net, robin@soal.org In-Reply-To: <5a8807d10801280718p6d52f689s3a13c4d8c6521a3f@mail.gmail.com> References: <5a8807d10801280520u7f8c7a9o8d2ab2efaa9c7644@mail.gmail.com> <1109819085.20080128151237@marcus-boerger.de> <5a8807d10801280718p6d52f689s3a13c4d8c6521a3f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Protected static props redeclared as public share value across classes From: helly@php.net (Marcus Boerger) Hello Robin, I checked it out in more detail and it is indeed broken as in it is not consistent: [marcus@zaphod PHP_5_3]$ php -r 'class A { protected static $p=1; } class B extends A { protected static $p=2; } ReflectionClass::Export("B");' -> works == 2 properties -> but should fail because of changed value [marcus@zaphod PHP_5_3]$ php -r 'class A { protected static $p=1; } class B extends A { public static $p=2; } ReflectionClass::Export("B");' Fatal error: Cannot change initial value of property static protected A::$p in class B in Command line code on line 1 [marcus@zaphod PHP_5_3]$ php -r 'class A { public static $p=1; } class B extends A { protected static $p=2; } ReflectionClass::Export("B");' Fatal error: Access level to B::$p must be public (as in class A) in Command line code on line 1 [marcus@zaphod PHP_5_3]$ php -r 'class A { public static $p=1; } class B extends A { public static $p=2; } ReflectionClass::Export("B");' -> works == 2 properties -> but should fail becasue of changed value So we need to fix this. marcus Monday, January 28, 2008, 4:18:50 PM, you wrote: > Hi Marcus, > Thanks for the prompt reply and explanation. I have some further > questions though: >> If the base class had the property defined as private >> then the property is private to that specific class and not directly >> accessible by derived classes that is it's name gets prefixed with the class >> name.. So in: >> class A { private static $p; } class B extends A { private static $p; } >> we have two different properties: > Understood. But if we have two separate properties for the reason that > A::$p is not visible to B, then how about these cases? > class A { protected static $p; } class B extends A { protected static $p; } > class A { public static $p; } class B extends A { public static $p; } > In both of those cases, A::$p is visible to the derived class, but the > re-declaration results in A::$p and B::$p being two separate > properties (see pastebin.com/fca2cd5b and pastebin.com/f4f94b32d for a > demonstration). This is one of the reasons I find the case where we > end up with only one property value to be surprising. > Another reason is that, as illustrated in my previous post, PHP's > behaviour doesn't seem to correlate with the inheritance rules of > other languages I'm familiar with: you always end up with two distinct > static properties in Java, C++ and C# (though of course I understand > this fact on its own is does not mean PHP is wrong :). > Lastly, with overridden static methods, PHP always yields two distinct > methods, regardless of the visibility modifiers. See > http://pastebin.com/f27f009c4 . Granted, with methods any other > behaviour would be very odd indeed, but it does emphasize an > inconsistency between method and property inheritance rules in PHP. > So for now I continue to feel this is a little strange. Any further > explanations would be greatly appreciated. :) > Thanks, > Robin >> Best regards, >> Marcus Best regards, Marcus