Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68989 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44822 invoked from network); 10 Sep 2013 08:46:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2013 08:46:12 -0000 Authentication-Results: pb1.pair.com header.from=happy.melon.wiki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=happy.melon.wiki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.174 as permitted sender) X-PHP-List-Original-Sender: happy.melon.wiki@gmail.com X-Host-Fingerprint: 209.85.216.174 mail-qc0-f174.google.com Received: from [209.85.216.174] ([209.85.216.174:58356] helo=mail-qc0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/B4-03199-35CDE225 for ; Tue, 10 Sep 2013 04:46:12 -0400 Received: by mail-qc0-f174.google.com with SMTP id n9so1662205qcw.33 for ; Tue, 10 Sep 2013 01:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=J+MsA0TQqTnjqycEuCu9/2aHfB2qB40xBt+fj4AG6DQ=; b=G7Em5ViSBOgyU3yy8JDqNqoGlC4ZpgrnS99zJQ6ZR7ygSuARZFZ6/epRFMNvOLE2ho dJSvCTdp5Rt1xDcjC0hCQgKlyyRQjctaN4kXnIKG0LivPjOEGnr9WBAYL2L5JFL0CjGZ TtYvsRVWXUeTbVscEh4jryq5U0YB6JRK01LHlXhuYgL8QefrKiOqJs6UgCnik0GHIUXK zKyEyr/Xx3FHDEiuGBc1U1fXYwpB0AefW0Kq++O8wZGZGl4F8pXiLmaht9juJ5dL4Pmi rfmjO6P4ptA89XC/g8Jqaooz6byN7uv8SfusE7ydNU1nmMFdhu/0mzqO8WrIj2Ao0XST XE3g== MIME-Version: 1.0 X-Received: by 10.49.3.194 with SMTP id e2mr30168265qee.21.1378802769299; Tue, 10 Sep 2013 01:46:09 -0700 (PDT) Sender: happy.melon.wiki@gmail.com Received: by 10.140.27.236 with HTTP; Tue, 10 Sep 2013 01:46:09 -0700 (PDT) In-Reply-To: References: Date: Tue, 10 Sep 2013 09:46:09 +0100 X-Google-Sender-Auth: YYCsHxqFoc55UFd8myB2bCulPjs Message-ID: To: Nikita Popov Cc: Daniel Macedo , PHP internals Content-Type: multipart/alternative; boundary=047d7bb0473447c19b04e60389f1 Subject: Re: [PHP-DEV] Re: [RFC] Named parameters From: happy.melon.wiki+gb@gmail.com (George Bond) --047d7bb0473447c19b04e60389f1 Content-Type: text/plain; charset=ISO-8859-1 What about: class Giant { public function foo( $height, $width ) { ... } } class FallenOverGiant extends Giant { public function foo( $width, $height ) { ... } } There's nothing to stop you doing that; I think it's actually done in some of the codebases I work on. Or: class Rectangle { public function paint( $height, $width ) { ... } } class Square extends Rectangle { public function paint( $width, $unused = null ) { return parent::paint( $width, $width } } Here I don't *want* someone to be able to use the second parameter (you can argue over whether the inheritance should be that way round, but that's the way code is currently written). I don't think there's a clever way of pleasing everyone here. In which case, the principle of least surprise definitely applies. Crawling the inherited signatures definitely feels like a shim rather than clever design. --G On 9 September 2013 23:27, Nikita Popov wrote: > On Mon, Sep 9, 2013 at 9:39 PM, Daniel Macedo wrote: > > > Nikita, > > > > I agree with your views, although, I think your last suggestion comes > > close to being close to some sort of weird method overloading (the way > > I understood it). > > > > Uh, I think this is a misunderstanding caused by my bad phrasing. I'll try > to clarify: > > class A { > public function foo($oldBar) { ... } > } > > class B extends A { > public function foo($newBar) { ... } > } > > $b->foo(oldBar => $xyz); > > Here `$b->foo()` will call `B::foo()`, *not* `A::foo()`. The thing about > looking at the parameter names of the parent methods is just to make sure > calls are compatible with the parameter names of parent methods, even if > those names were changed during inheritance. We do not actually call the > parent method, we just borrow the parameter name from there. > > > In fact I'm not sure if the other way around should be the norm; where > > we'd force the dev to implement the *same* args as the parent (like it > > is now: i.e. type hinting, same signature, etc); even if it's just to > > do an unset($oldbar) inside something like B::foo($newBar, $oldBar = > > NULL) > > > Yes, throwing an error during the signature validation is the "right" thing > to do from a theoretic point of view. The issue is just that it breaks old > code which didn't make sure that parameter names between parent and child > lined up. "Break" is a bit too much here as it would still run, just > throwing an E_STRICT. This is what I'd like to go for, but others disagree > so I tried to offer an alternative solution. > > Nikita > --047d7bb0473447c19b04e60389f1--