Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55520 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27268 invoked from network); 19 Sep 2011 09:03:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2011 09:03:58 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 207.97.245.163 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 207.97.245.163 smtp163.iad.emailsrvr.com Linux 2.6 Received: from [207.97.245.163] ([207.97.245.163:39138] helo=smtp163.iad.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E3/06-14600-775077E4 for ; Mon, 19 Sep 2011 05:03:57 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp56.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 062AD3D8360; Mon, 19 Sep 2011 05:03:48 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp56.relay.iad1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 5A9533D8332; Mon, 19 Sep 2011 05:03:46 -0400 (EDT) Message-ID: <4E770572.2040506@sugarcrm.com> Date: Mon, 19 Sep 2011 02:03:46 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: Gustavo Lopes CC: "internals@lists.php.net" References: <4E74E5A0.2030006@sugarcrm.com> <4E76320F.6010904@sugarcrm.com> <4E764137.9080507@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] __constructor parameter limitations. From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! On 9/19/11 1:40 AM, Gustavo Lopes wrote: > 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 Why would it always be? I had code where overriding class had methods that need less arguments and substituted defaults or overrode values for some parameters. I never had a code (which survived longer than 2 minutes without editing) where one just forgot to specify arguments to a method that's using them - any half-decent IDE would discover that in seconds and alert you. I don;t think it's a place of the engine to decide perfectly valid language use is a "mistake" and throw errors just because somebody dislikes it. > 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 Most languages that check signatures are compiled languages, in which variable arguments are implemented differently than in PHP. For example, Python doesn't have this kind of signature enforcement at all (so you could claim it allows this type of contravariance, too) - and yet you don't think this is the reason we have to abandon it, right? > 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. In this particular case it would not be right, but it's not the reason to prohibit it in many other cases where it is. The fact that you can write wrong code if you try really hard shouldn't be a reason to prevent perfectly correct code from working. > * Allow arguments with a supertype. For instance, this should give no > warning: > * Allow extra parameters with a default value (implemented): * Allow ignoring parameters or introducing defaults * Remove fatal errors. Fatal errors should be when the engine can not continue, not when the code is perfectly workable but we frown upon such use of the language. This is especially true in non-compiled language where all fatal errors break application in runtime. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227