Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55553 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11934 invoked from network); 19 Sep 2011 15:53:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2011 15:53:53 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.42 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:57290] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/80-07992-F85677E4 for ; Mon, 19 Sep 2011 11:53:53 -0400 Received: by ywa8 with SMTP id 8so4935667ywa.29 for ; Mon, 19 Sep 2011 08:53:49 -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=9qRR2WUyJXvPpFuFZpkYrymD1URd0ZChj1CljXUiol4=; b=wN8GUKvy8MmM6ekaXDBisES2lnaJWPellhtXWGthbJ6XMUwu0eXtHnWPkcLtuMYMsv rDYUN28Xy5HJI45QZHOxVtCO8lbWVPP/7iZmVNi/dnSlZCi1Oxdr5kvMmuZbbM++J+aU 7Nf7Ns7efYKB5HMY3l2Yy0RUrajnHOaUxZl0c= MIME-Version: 1.0 Received: by 10.236.192.198 with SMTP id i46mr15065455yhn.130.1316447627922; Mon, 19 Sep 2011 08:53:47 -0700 (PDT) Received: by 10.147.125.13 with HTTP; Mon, 19 Sep 2011 08:53:47 -0700 (PDT) In-Reply-To: References: <4E74E5A0.2030006@sugarcrm.com> <4E76320F.6010904@sugarcrm.com> <4E764137.9080507@sugarcrm.com> <4E7685DE.6010805@sugarcrm.com> <4E768C86.3030307@sugarcrm.com> <4E769418.6040200@sugarcrm.com> <4E770163.2090001@sugarcrm.com> <4E770770.60809@sugarcrm.com> Date: Mon, 19 Sep 2011 17:53:47 +0200 Message-ID: To: Etienne Kneuss Cc: Anthony Ferrara , Laruence , Gustavo Lopes , 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) First of all, Anthony, thanks for joining into the discussion! >> With respect to the func_get_args argument, I see that as a non-issue. >> =C2=A0Sure, you can do it. =C2=A0But if you do, you're lying about the >> interface. =C2=A0You're telling the callers that you expect no arguments= , >> but then all of a sudden you error out. > > > Well, we have no way of declaring that we accept an undefined number of > arguments. So there is simply no choice here. maybe we should consider adding support for that, as I agree that it would make the contract more clear. >> =C2=A0You're pushing all of the >> interface declaration logic out of the interface and into code. >> That's only going to create maintainability, readability and quality >> issues as time goes on. =C2=A0Realistically, the only good use of >> func_get_args is when you need to take in an unlimited number of >> arguments. =C2=A0But if you do that, you should include the minimum numb= er >> in the API itself. =C2=A0So if you have a function add() that can take a= ny >> number of integers, the minimum that makes sense is 2. =C2=A0So you shou= ld >> declare add($left, $right), and then use func_get_args to get all of >> them to add together. =C2=A0However, with that said, I'd argue that it's >> bad design to do that at all. =C2=A0I'd recommend instead taking an arra= y >> parameter and adding the elements of the array. =C2=A0Not only is it >> cleaner and easier to understand, it also solves the problem of >> extending that functionality (so you're not duplicating the >> func_get_args in each child)... >> > > By doing that, you also do exactly what you describe earlier, you push th= e > args checks in the code itself, as you could always pass an incomplete > array, and you could error out earlier. > > Var-args functions have been quite used for many things, there is no reas= on > why we should flag that as bad practice now... is there? > not that I know of, except that we have no explicit way to declare signatur= e. to reflect to the original points by Anthony: bringing up the Square - Rectangle example was a bad one, but to quote from the wikipedia entry: "Violations of LSP, like this one, may or may not be a problem in practice, depending on the postconditions or invariants that are actually expected by the code that uses classes violating LSP. Mutability is a key issue here. If Square and Rectangle had only getter methods (i.e. they were immutable objects), then no violation of LSP could occur." So while it can cause violation, it isn't a violation by itself. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu