Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89043 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1765 invoked from network); 2 Nov 2015 16:42:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Nov 2015 16:42:35 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.180 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:34606] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/77-42726-A7297365 for ; Mon, 02 Nov 2015 11:42:34 -0500 Received: by wikq8 with SMTP id q8so55385796wik.1 for ; Mon, 02 Nov 2015 08:42:32 -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=1uxP+QXByXs2POsj/8EN9CU0T5U3CD9wsn6l2fvmvng=; b=SoFvLvH1fiOYdJT6V0Gmqma5xZk+9E0X4QANyo6e/62GeU18dpM1SIqfx6FUXUywFi 5QU68XuzqVvLdHbmyrqE0EEle0rsCAww/O5TEawtEHGUzIMhjBsC0BwzC6smCUs37vw3 wZeSsV9WOZZcl455q30YpJc+RcP4XQtGwTTEDqZl2pCEjV5H4h6ObbKdBrALxsDbCPsK EyxlBTMwE+svAZgamk3B84twlnzgdMrKQCUIk74uqMbWV2p/WG8l7nXc+7Rrvh2Il0Q3 ELs0IK2AfBH+J3AsbQ5GOvwzdniKMDa1i5absevW0epIZINpl6vUdXBSpR3vXWUMMNfP K1bw== X-Received: by 10.194.184.7 with SMTP id eq7mr24337458wjc.26.1446482552078; Mon, 02 Nov 2015 08:42:32 -0800 (PST) Received: from [192.168.0.136] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id d22sm18974071wma.21.2015.11.02.08.42.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Nov 2015 08:42:31 -0800 (PST) To: PHP internals list References: <56372B62.1000206@gmail.com> Message-ID: <56379241.2080900@gmail.com> Date: Mon, 2 Nov 2015 16:41:37 +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: 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) 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) Thus this is acceptable: class Foo { public function test() {} } class Bar extends Foo { public function test($foo = null) {} } But these are all not: class Foo2 { public function test($foo = null) {} } class Bar2 extends Foo2 { // Doesn't accept one parameter public function test() {} } class Baz2 extends Foo2 { // Doesn't accept zero parameters public function test($foo) {} } class Foo3 { public function test() {} } class Bar3 extends Foo3 { // Doesn't accept zero parameters public function test($foo) {} } Variadic signatures count as "zero or more" when the parent accepts only zero: class Foo4 { public function test() {} } class Bar4 extends Foo4 { public function test(...$foo) {} } But where the parent accepts "zero or one", the following ought to be compatible because calls with no parameters, and calls with one parameter, would both be valid: class Foo { public function test($foo = null) {} } class Bar extends Foo { public function test(...$foo) {} } In short, I agree with you that this warning is incorrect, but will leave this here in case anybody else is equally confused (and becomes any less so by reading this...) Regards, -- Rowan Collins [IMSoP]