Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34966 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32299 invoked by uid 1010); 28 Jan 2008 17:03:03 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 32284 invoked from network); 28 Jan 2008 17:03:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2008 17:03:03 -0000 Authentication-Results: pb1.pair.com header.from=jochem@iamjochem.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jochem@iamjochem.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iamjochem.com from 194.109.193.121 cause and error) X-PHP-List-Original-Sender: jochem@iamjochem.com X-Host-Fingerprint: 194.109.193.121 mx1.moulin.nl Linux 2.6 Received: from [194.109.193.121] ([194.109.193.121:56454] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/11-25507-5CA0E974 for ; Mon, 28 Jan 2008 12:03:02 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id C287A27D909; Mon, 28 Jan 2008 18:02:57 +0100 (CET) X-Virus-Scanned: amavisd-new at moulin.nl Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FG8d26oQPliZ; Mon, 28 Jan 2008 18:02:53 +0100 (CET) Received: from [192.168.1.10] (bspr.xs4all.nl [194.109.161.228]) by mx1.moulin.nl (Postfix) with ESMTP id A744E27D808; Mon, 28 Jan 2008 18:02:53 +0100 (CET) Message-ID: <479E0ABE.5080005@iamjochem.com> Date: Mon, 28 Jan 2008 18:02:54 +0100 User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Marcus Boerger CC: Robin Fernandes , internals@lists.php.net, robin@soal.org References: <5a8807d10801280520u7f8c7a9o8d2ab2efaa9c7644@mail.gmail.com> <1109819085.20080128151237@marcus-boerger.de> <5a8807d10801280718p6d52f689s3a13c4d8c6521a3f@mail.gmail.com> <868592137.20080128174926@marcus-boerger.de> In-Reply-To: <868592137.20080128174926@marcus-boerger.de> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Protected static props redeclared as public share value across classes From: jochem@iamjochem.com (Jochem Maas) Marcus Boerger schreef: > 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. I don't get the 'but should fail because of changed value' - isn't the changed value akin to overloading a method - where the body of the method changes (obviously)? I also surmise that the issue becomes more tricky if you consider late static binding, which I am assuming is still scheduled for php6, and as such it may be worth holding back making a fix until it is clearer what the larger ramifications are? > > 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 >