Newsgroups: php.internals,php.qa Path: news.php.net Xref: news.php.net php.internals:36609 php.qa:64111 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52359 invoked from network); 27 Mar 2008 09:50:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Mar 2008 09:50:37 -0000 Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; 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:39498] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/14-32389-CED6BE74 for ; Thu, 27 Mar 2008 04:50:37 -0500 Received: from dhcp-172-28-202-230.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 1EB1811CF57; Thu, 27 Mar 2008 10:50:34 +0100 (CET) Date: Thu, 27 Mar 2008 10:50:33 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1124764115.20080327105033@marcus-boerger.de> To: "Marco Kaiser" CC: "PHP Developers Mailing List" , In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-QA] BC break with php 5.2.6 From: helly@php.net (Marcus Boerger) 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