Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55516 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21280 invoked from network); 19 Sep 2011 08:40:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2011 08:40:59 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:43469] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/D4-14600-810077E4 for ; Mon, 19 Sep 2011 04:40:57 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 3F668700039F for ; Mon, 19 Sep 2011 09:40:53 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id ZF3Ow4hC3vu5 for ; Mon, 19 Sep 2011 09:40:53 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id F36BB7000398 for ; Mon, 19 Sep 2011 09:40:52 +0100 (WEST) Received: from clk-0081.mshome.net (unknown [85.139.253.17]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id D5E832007982 for ; Mon, 19 Sep 2011 09:40:52 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <4E74E5A0.2030006@sugarcrm.com> <4E76320F.6010904@sugarcrm.com> <4E764137.9080507@sugarcrm.com> Date: Mon, 19 Sep 2011 09:40:51 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: <4E764137.9080507@sugarcrm.com> User-Agent: Opera Mail/11.51 (Win32) Subject: Re: [PHP-DEV] __constructor parameter limitations. From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") 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 > preconditions 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 = $foo + 1; } It is obvious that in this case a subclass override that takes no arguments cannot possibly satisfy the contract of the original method. That is to say, 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: