Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55532 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46567 invoked from network); 19 Sep 2011 09:35:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2011 09:35:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.170 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:45231] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/7A-14600-5FC077E4 for ; Mon, 19 Sep 2011 05:35:50 -0400 Received: by gxk10 with SMTP id 10so1403823gxk.29 for ; Mon, 19 Sep 2011 02:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xxuRqxU0ABNcdyc2U6pgFykkVbuItBht+v8tF+U21Xc=; b=vEbNH3QXLYs1/NkDWMHQyG+ElttDC1GuiBz/gs7et0uZfwJFPBvl7ziVx9xliIDZD6 I819U1TRQvL74+DLBZwg1/lez4xFLCCs6744vV6tUXIfXlXaIdl1M14YSrmy5fAOFrwl ecT0e/V9h6ES1iujw36UDZ1PF2UCQiQKP/cv4= MIME-Version: 1.0 Received: by 10.236.177.72 with SMTP id c48mr12180700yhm.79.1316424947247; Mon, 19 Sep 2011 02:35:47 -0700 (PDT) Received: by 10.147.125.13 with HTTP; Mon, 19 Sep 2011 02:35:47 -0700 (PDT) In-Reply-To: References: <4E74E5A0.2030006@sugarcrm.com> <4E76320F.6010904@sugarcrm.com> <4E764137.9080507@sugarcrm.com> Date: Mon, 19 Sep 2011 11:35:47 +0200 Message-ID: To: Gustavo Lopes Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] __constructor parameter limitations. From: tyra3l@gmail.com (Ferenc Kovacs) On Mon, Sep 19, 2011 at 10:40 AM, Gustavo Lopes wr= ote: > Em Sun, 18 Sep 2011 20:06:31 +0100, Stas Malyshev > escreveu: > >> On 9/18/11 11:23 AM, Nikita Popov wrote: >>> >>> to tell you: I need this and that method accepting these and these >>> arguments to work correctly. If the signature isn't enforced, this >>> doesn't make sense anymore. You could just as well drop the signature >>> from abstract method definitions, as it's pointless then. >> >> No it is not. The signature tells "this method would accept certain >> arguments". If you call it with these arguments, it would work. However, >> there's no promise to never extend the cases where it works - it goes >> contrary to the whole point of OOP to say "I will never loosen precondit= ions >> on my methods". > > While this is true, we should be a bit pragmatic here. > > If the subclass method specifies less parameters, it is very likely a > mistake. It's not usual (certainly it's not more frequent than a mistake > being the case) for arguments to be simply intentionally ignored. In fact= , I > don't know of any popular language that implements this type of > contravariance. Plus, consider the case in which the superclass takes an > argument by reference: > > function increment(&$foo) { $foo =3D $foo + 1; } > > It is obvious that in this case a subclass override that takes no argumen= ts > cannot possibly satisfy the contract of the original method. That is to s= ay, > by ref arguments are also used for postconditions. > > That said, I think the only rules worth implementing are: > > * Allow arguments with a supertype. For instance, this should give no > warning: > > class A {} > class B extends A {} > class C { function g(B $b) {} } > class D extends C { function g(A $a) { } } > > * Allow extra parameters with a default value (implemented): > > class C { function g($a) {} } > class D extends C { function g($a,$b=3Dtrue) { } } > could you check my second(lengthy) mail on this thread? I also tried to come up with the valid, and invalid signature changes. I forget to take references into account, so thanks for pointing that out. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu