Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49944 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87775 invoked from network); 21 Oct 2010 07:52:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2010 07:52:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:43829] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/A2-03733-931FFBC4 for ; Thu, 21 Oct 2010 03:52:26 -0400 Received: by bwz13 with SMTP id 13so53824bwz.29 for ; Thu, 21 Oct 2010 00:52:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=Wj8USiSjSeB1vqzdQXVkXgXabbIb22rNkNi5qJ9xZOw=; b=tKFEZTrXoyJJWccBHivFRxnobVm7MqKFs4J1nCNTwUlYHgwmbiJXEqCseRK0zhbfj6 w04jPqcojTodR+9NX4MoPSOYW46EyTE1qYWf/4RO66ZCsNMZt0lceBYDlHPmiYgBlCX8 i1dPPFKbccdc56QS0BVA7qRPMByOt37ojpOvk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=JzepiEAu98DyE4OOSjwUjVkL7up431WX0hpfGVFrQ2findMpcPuSL1vf8M4i+RGOLY J8IS/X1WFuXcL/QEFUHZFDPxWZRrwjYNbT43h3wi0S6JE4sF6r7W0jbgfrrl1vf0uW8I +yyeuAeLNZ5jA6KOeWqtN0vlTan9pBhnS3ULs= Received: by 10.204.59.19 with SMTP id j19mr368226bkh.124.1287647542608; Thu, 21 Oct 2010 00:52:22 -0700 (PDT) Received: from l.local ([82.76.132.251]) by mx.google.com with ESMTPS id t10sm922894bkj.4.2010.10.21.00.52.20 (version=SSLv3 cipher=RC4-MD5); Thu, 21 Oct 2010 00:52:21 -0700 (PDT) Message-ID: <4CBFF13B.5060404@gmail.com> Date: Thu, 21 Oct 2010 10:52:27 +0300 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: PHP internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Skipping of defaulted parameters. From: ionut.g.stan@gmail.com ("Ionut G. Stan") On 20/Oct/10 2:58 PM, Richard Quadling wrote: > Hello. > > Take the following simple code. > > function foo($var1, $var2 = 2, $var3 = 3) { > echo "$var1, $var2, $var3\n"; > } > > foo(10); // 10, 2, 3 > foo(10, 20); // 10, 20, 3 > foo(10, 20, 30); // 10, 20, 30 > foo(10, null, 30); // 10, , 30 > foo(10,, 30); // Parse error. > ?> > > According to the manual > > A variable is considered to be null if it has not been set to any value yet [1]. > By default, function arguments are passed by value [2]. > When using default arguments, any defaults should be on the right side > of any non-default arguments. [3] > > > From this, the question I have is what do I pass when I want to use > the default, WITHOUT having to supply the default value itself. > > On the surface, null should work. Null (according to [1]) is > specifically saying that there is no value. But it is being > interpreted as a value. > > I'm guessing the reason for null being interpreted as a value is > really that the supplied argument count is used and any unsupplied > arguments are defaulted. > > But null isn't a value ... that seems to be REALLY important to me. > But from userland it is a value. Just a really odd one. > > I would argue that by having a null in the arguments, the intent is to > NOT supply a value and have the default value used in the function. > > > Possible solutions. > > 1 - Do nothing in core and implement is_null() checking to reinstate > the default value. > > function foo($var1, $var2 = 2, $var3 = 3) { > $var2 = is_null($var2) ? 2 : $var2; > $var3 = is_null($var3) ? 3 : $var3; > echo "$var1, $var2, $var3\n"; > } > > > 2 - Allow null to be supplied and have the default value be used for > the argument. > > foo(10, null, 30); // would output 10, 2, 30 > > > 3 - New keyword of default or void to specifically indicate the intent > to use the default value for the argument. > > foo(10, default, 30); // would output 10, 2, 30 > > > 4 - Allow missing arguments to default. > > foo(10,, 30); // Parse error. > > > > Option 4 would probably be the worse one to go for. Looking any number > of languages that support defaults and you will see code like ... > > someFunction(param1,,,,,param7,,,,param11) > > sort of thing. > > > > Option 3, whilst does clearly indicate the intent, does introduce a > new keyword. As a non core dev, I'm guessing we end up with naming > conflicts. And something called "default" is probably going to be a > big one. "Void" also. > > But using something like _ (yep, underscore), could be a solution here [4]. > > > > Option 2, after probably having to reject option 3, would be my > choice. I want null to REALLY mean nothing. Just like it would be in > foo(10). > > > > Option 1 is what I have to do at the moment. Option 5: Implement named parameters? -- IonuČ› G. Stan | http://igstan.ro