Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89048 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45454 invoked from network); 3 Nov 2015 09:21:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Nov 2015 09:21:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.172 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.172 mail-wi0-f172.google.com Received: from [209.85.212.172] ([209.85.212.172:37257] helo=mail-wi0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/32-13519-4BC78365 for ; Tue, 03 Nov 2015 04:21:57 -0500 Received: by wicfv8 with SMTP id fv8so7325086wic.0 for ; Tue, 03 Nov 2015 01:21:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=PRqfFBUJCJ4y3MB6pVG1psvgRcKnYIuhWWlXhm8CTdg=; b=OtCRQ5Kz/SEb9T7UAnAPUx2blq2X3eBREy9Y+FWpm3W4ajOU2eiXgQh5Wm/6qXnTsy uYbIAGMt60w/sRBhmrPRmpFe0oX+ncuva8zu8/armZd6fuyjQnsvBwdvUFo9q9o9DmUO NirIQGrMJ2lld6w+g2EHo9N0F7InnE6hZBFLfsRx1vQFs/81Lc3Xnlz4i5bPCiWAHoO5 I8cmYwx8jZWywgMZQdxU9z7a7o5zK3xA1zNQdOQUsTnfpTB1y8BzPmiKshFlKCTdv8aN pXlY9ffTq6ipKIURDTmIy+enR2GcSqX3w/veoWJmCVKQ5rKfFmny2j0aajh79gcvnEQg Atuw== X-Received: by 10.194.175.226 with SMTP id cd2mr32065130wjc.30.1446542513788; Tue, 03 Nov 2015 01:21:53 -0800 (PST) Received: from [192.168.0.136] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id lf10sm26538596wjb.23.2015.11.03.01.21.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Nov 2015 01:21:51 -0800 (PST) To: internals@lists.php.net References: <56372B62.1000206@gmail.com> <56379241.2080900@gmail.com> <5637BD0B.1000805@mabe.berlin> Message-ID: <56387C76.8030106@gmail.com> Date: Tue, 3 Nov 2015 09:20:54 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5637BD0B.1000805@mabe.berlin> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [Question] Variadic method signature compatibility between 5.6 and 7.0 From: rowan.collins@gmail.com (Rowan Collins) Marc Bennewitz wrote on 02/11/2015 19:44: > Hi Rowan, > > On 11/02/2015 05:41 PM, Rowan Collins wrote: >> Alexander Lisachenko wrote on 02/11/2015 11:12: >>> First definition declares exactly one single parameter, which can be >>> absent during the method call, so I can even write >>> >>> public static function test() {} >>> >>> Second definition defines zero or more arguments, so it can be also >>> described by the same signature: >>> >>> public static function test() {} >> >> OK, I got a bit confused with the different optional parameters, and >> neither your explanation nor Andrea's quite did it for me. >> >> But, I think you're right that this should be compatible, if the rule >> is "any legal call on the parent should also be legal on the child". >> Currently, all versions of PHP enforce the following: >> >> - if parent accepts no parameters, child must accept zero, but could >> accept one or more optional parameters >> - if parent accepts zero or one (an optional parameter), child must >> accept zero, must accept one, but could accept more (so, two optional >> parameters is fine; no parameters at all is incompatible) >> > > In my opinion the warning is valid as the one method defines one > optional argument and the overwritten method would accept no or more > arguments where the no arguments is wrong: > https://3v4l.org/6eMiu > class Foo { > public function test($foo = null) {} > } > class Bar extends Foo { > public function test() {} > } That's not equivalent, because the version with no arguments explicitly prohibits zero arguments, which the variadic signature doesn't. You have to compare the possible calls, not convert them into signatures: class Foo { public function test($foo = null) {} } class Bar extends Foo { public function test(...$foo) {} } $a = new Foo; $a->test(); // valid $a->test(42); // valid $a->test(42, 6, 9); // NOT VALID $b = new Bar; $b->test(); // valid $b->test(42); // valid $b->test(42, 6, 9); // valid So any call which is valid on Foo is also valid on Bar. There are calls on Bar which are not valid on Foo, but that is not prohibited elsewhere: class Baz extends Foo { public function test($foo = null, $bar = null, $baz = null) {} } // no compilation warnings $c = new Baz; $c->test(); // valid $c->test(42); // valid $c->test(42, 6, 9); // valid Regards, -- Rowan Collins [IMSoP]