Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:36613 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82371 invoked from network); 27 Mar 2008 13:12:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Mar 2008 13:12:54 -0000 Authentication-Results: pb1.pair.com header.from=marco.kaiser@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=marco.kaiser@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 66.249.92.173 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: marco.kaiser@gmail.com X-Host-Fingerprint: 66.249.92.173 ug-out-1314.google.com Received: from [66.249.92.173] ([66.249.92.173:42323] helo=ug-out-1314.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/72-02016-55D9BE74 for ; Thu, 27 Mar 2008 08:12:53 -0500 Received: by ug-out-1314.google.com with SMTP id u40so318360ugc.29 for ; Thu, 27 Mar 2008 06:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:from:to:cc:references:in-reply-to:subject:date:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language:message-id; bh=8fQgVlZltE2OiCGJ03ZpLHxxIJCyftIXM3Yv6/ubF04=; b=r004onYFq+iTIZMYLIZ+Ac1o/fhB21o6OtDMYHnsnjzNp6kr35BMJy8yipk4KrU7dSxoKTkzpjW1zYujIud10rBv6MweLpkiGbF9X2jEXmp82cIPB2993YlIlnRYv8cphinU3FJr4GeCCyRRpqDl5z0fJTW5L5lhibHoyBQ/fKk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=from:to:cc:references:in-reply-to:subject:date:mime-version:content-type:content-transfer-encoding:x-mailer:thread-index:content-language:message-id; b=GofiPzz0vBJVJQT0rjeEo6oRamztopjKLYTA5FGQuz1ozKhdGVPdiYZ75t2kqnywdChiycGQeWGqvUlsHwMdcH0M3VcmAb/0GMKEYj2fEfUJKMfx3j+X3FLQLqkusoCvinL1ELgnAtl9y/7BHoQ2AkyrIiauN5EbXo2As/j13y4= Received: by 10.78.138.14 with SMTP id l14mr4173843hud.63.1206623569813; Thu, 27 Mar 2008 06:12:49 -0700 (PDT) Received: from think ( [217.7.237.75]) by mx.google.com with ESMTPS id y2sm917698mug.9.2008.03.27.06.12.47 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 27 Mar 2008 06:12:48 -0700 (PDT) To: "'Marcus Boerger'" Cc: "'PHP Developers Mailing List'" , References: <1124764115.20080327105033@marcus-boerger.de> In-Reply-To: <1124764115.20080327105033@marcus-boerger.de> Date: Thu, 27 Mar 2008 14:08:32 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AciP8AF9LK3kQFaHQEu7mgX5ReumWgAGNfmg Content-Language: de Message-ID: <47eb9d50.02e2660a.759d.2e19@mx.google.com> Subject: RE: [PHP-QA] BC break with php 5.2.6 From: marco.kaiser@gmail.com ("Marco Kaiser") Hi Marcus, thanks for this conclusion. I just asked this because this changed in this release and should noticed in the readme or upgrade process because most singleton pattern implementations in some frameworks, for ie. ZF are using this code: class My_Controller_Front extends Zend_Controller_Front { public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } } The __constructor in Zend_Controller_Front is private. I asked a, i think, similar question last nov. About private properties. http://news.php.net/php.internals/33543 Johannes replied to this: http://news.php.net/php.internals/33544 Johannes: " That's a feature: Extended classes know nothing about private stuff in the parent class. Without that the encapsulation won't be complete." This means this "was maybe a bug, that i allread talked about" but its now changed so we should raise a notice about this. That will BREAK Many many apps out there. For example, PHPUNIT, ZendFramework, ezComponents. -- Marco > -----Original Message----- > From: Marcus Boerger [mailto:helly@php.net] > Sent: Thursday, March 27, 2008 10:51 AM > To: Marco Kaiser > Cc: PHP Developers Mailing List; php-qa@lists.php.net > Subject: Re: [PHP-QA] BC break with php 5.2.6 > > Hello Marco, > > Thursday, March 27, 2008, 9:25:48 AM, you wrote: > > > Hi, > > > i noticed that some changes was made that 100% break all apps that do > such > > stuff: > > > class x extends y > > { > > public static function foo() > > { > > new self(); > > } > > } > > > class y > > { > > private function __construct() > > { > > echo 'y::__construct()' . PHP_EOL; > > } > > } > > > x::foo(); > > > with php 5.2.5 i works so that i get an output "y::__construct()" but > with > > 5.2.6RC and -DEV > > it throws an fatal error: > > > Fatal error: Call to private y::__construct() from context 'x' > > The behavior is correct. Maybe something with $this is broken in > earlier > versions. I checked the basic issue here calling an inherited private > constructor directly without anything else involved: > > [marcus@zaphod PHP_5_0]$ php -r 'class R{private function > __construct(){}} class D extends R{} new D;' > make: `sapi/cli/php' is up to date. > > Fatal error: Call to private R::__construct() from context '' in > Command line code on line 1 > [marcus@zaphod PHP_5_0]$ cd ../PHP_5_1 > [marcus@zaphod PHP_5_1]$ php -r 'class R{private function > __construct(){}} class D extends R{} new D;' > make: `sapi/cli/php' is up to date. > > Fatal error: Call to private R::__construct() from context '' in > Command line code on line 1 > [marcus@zaphod PHP_5_1]$ cd ../PHP_5_2 > [marcus@zaphod PHP_5_2]$ php -r 'class R{private function > __construct(){}} class D extends R{} new D;' > make: `sapi/cli/php' is up to date. > > Fatal error: Call to private R::__construct() from invalid context in > Command line code on line 1 > [marcus@zaphod PHP_5_2]$ cd ../PHP_5_3 > [marcus@zaphod PHP_5_3]$ php -r 'class R{private function > __construct(){}} class D extends R{} new D;' > make: `sapi/cli/php' is up to date. > > Fatal error: Call to private R::__construct() from invalid context in > Command line code on line 1 > [marcus@zaphod php-cvs]$ cd ../php-cvs > [marcus@zaphod php-cvs]$ php -r 'class R{private function > __construct(){}} class D extends R{} new D;' > make: `sapi/cli/php' is up to date. > > Fatal error: Call to private R::__construct() from invalid context in > Command line code on line 1 > > Apparently all of 5.0, 5.1, 5.2, 5.3 and HEAD behave in the same way > and issue a > Fatal error as expected. > > Now your code uses self winthin class X which is derived from Y which > has a > private constructor. Let's see whether the ctor is illegally called in > this > example: > > [marcus@zaphod PHP_5_0]$ cd ../PHP_5_0 > [marcus@zaphod PHP_5_0]$ php -r 'class R{private function > __construct(){echo "R\n";}} class D extends R{static function > f(){var_dump(new self);}} D::f();' > make: `sapi/cli/php' is up to date. > R > object(D)#1 (0) { > } > [marcus@zaphod PHP_5_0]$ cd ../PHP_5_1 > [marcus@zaphod PHP_5_1]$ php -r 'class R{private function > __construct(){echo "R\n";}} class D extends R{static function > f(){var_dump(new self);}} D::f();' > make: `sapi/cli/php' is up to date. > R > object(D)#1 (0) { > } > [marcus@zaphod PHP_5_1]$ cd ../PHP_5_2 > [marcus@zaphod PHP_5_2]$ php -r 'class R{private function > __construct(){echo "R\n";}} class D extends R{static function > f(){var_dump(new self);}} D::f();' > make: `sapi/cli/php' is up to date. > > Fatal error: Call to private R::__construct() from context 'D' in > Command line code on line 1 > > So yes, there is a bug with the inheritance rules in older versions. > > > i can remember that i asked a related question last year and someone > told me > > it is ok so and its a know behavior. > > This change will ie. break ZF too. Any suggestions to this behavior? > > Fix the code by finding the correct way that works with both old and > new > versions. > > Best regards, > Marcus