Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60185 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54629 invoked from network); 18 Apr 2012 11:31:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2012 11:31:37 -0000 Authentication-Results: pb1.pair.com header.from=admacedo@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=admacedo@gmail.com; spf=pass; 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: admacedo@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:40963] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/B9-03614-816AE8F4 for ; Wed, 18 Apr 2012 07:31:36 -0400 Received: by ggmb2 with SMTP id b2so4022371ggm.29 for ; Wed, 18 Apr 2012 04:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=jCLnHSUbs1Eyj11zCEgmfV2wyR2URRTZZG5IQRplilU=; b=RXpI71wC21xditBOCFWZwrpnUT531fyhh+cjGKJ3QC0of4niSdwwlGeVPjWUqthXjb KdYXMBIe3sbknmlKc/BcQs4x79myhpv+zRzr41wIPy0xQHtW8QNoftRQ6KDsv29MN4Tp grp2M8dZ4P6LD4JhD0MqZ6d3zCYkCjRWnQv/yc7hjtfpzfeG+3qpYETfg+NPvbDvenrn E21ZvBcJQG3jp14EPPJHASl3u5gZuMkZVXRmyYFfnYD45AlYCoDbkWSwPeuAGqG+LIAG DU/ThzSbWTDgT2aK0yBl7wc8WERP4OpN0F+qSSZnrIzXrPo7vsclGpGwUwB/rXPwOyl0 Y5lQ== Received: by 10.236.189.2 with SMTP id b2mr1822854yhn.11.1334748693861; Wed, 18 Apr 2012 04:31:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.46.130 with HTTP; Wed, 18 Apr 2012 04:30:53 -0700 (PDT) In-Reply-To: <4F8E9E1E.8050207@lsces.co.uk> References: <4F8DF4B1.2040307@sugarcrm.com> <4F8E9E1E.8050207@lsces.co.uk> Date: Wed, 18 Apr 2012 12:30:53 +0100 Message-ID: To: Lester Caine Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] skipping optional parameters From: admacedo@gmail.com (Daniel Macedo) I am sorry Lester, but you seem to be getting the "optional parameter" backwards. You are supposed to use the optional parameters when it's up to the library/function definition to determine it's value, not when the value is what you want for this particular function call! What you seem to be currently reading from a function definition when using it is i.e.: "This parameter's default is TRUE? That's what I need it to be here, skip typing it!" This is the wrong approach for proper design, and you will have a lot of headaches when refactoring! If you use them *properly*, what you read when using the function call is "I don't need/want to change the default value for this optional parameter, use what the library determines!", this is the proper way to use a function call with optional parameters, that will give you a LOT less headaches! The problem with the way things work currently, is that the default value, is now *hard coded* into all function calls were you wanted to use the default, but needed to define a latter optional parameter! Hence the proper use would be to either use a reserved word, or having named parameters. I personally think there's a place for having both. > Daniel Macedo wrote: >> >> function fn1($a =3D false, $b =3D nul, $c =3D 1) >> { >> =A0 var_dump($a, $b. $c); >> } >> >> // your idea >> fn1(NULL, NULL, 10), // NULL, NULL, 10 >> >> // vs. using a reserved word >> fn1(default, default, 10), // FALSE, NULL, 10 > > > Of cause one little problem here is if the default gets changed in the > 'library' then every use of 'default' would need to be checked. > Of cause the same problem applies with changing defaults that are used by > leaving out the latter parameters on the list, but this just adds another > area that needs cross checking. Always including the parameters needed is > the safe way in many cases anyway! So leaving them off can be bad practic= e > anyway? > > > -- > Lester Caine - G8HFL > ----------------------------- > Contact - http://lsces.co.uk/wiki/?page=3Dcontact > L.S.Caine Electronic Services - http://lsces.co.uk > EnquirySolve - http://enquirysolve.com/ > Model Engineers Digital Workshop - http://medw.co.uk// > Firebird - http://www.firebirdsql.org/index.php > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >