Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49938 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5858 invoked from network); 20 Oct 2010 11:59:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2010 11:59:02 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.177 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.177 mail-qy0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:39327] helo=mail-qy0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DF/F0-00933-489DEBC4 for ; Wed, 20 Oct 2010 07:59:01 -0400 Received: by qyk4 with SMTP id 4so2495822qyk.8 for ; Wed, 20 Oct 2010 04:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:reply-to:from :date:message-id:subject:to:content-type; bh=AN2cvlgZZxcuj97GV3eXLFQRB30C00ZyfU4bo65sXRI=; b=L64EXNNDZx7LeFFPrkDydY/87NG/uZDOLES5S7whmJXIOrMS8zB+Nimqz964dnCK9f XFDnMYGf+NpaJ3+z3D5IWoJoSZbj50YxKMKWnj6MWzncqaapNVilVE0zPT2PMVPx/QEN Dg+49nGmZIRgcFwkCA4BcXzVupL65Dwilasuk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:from:date:message-id:subject:to:content-type; b=lSWu7cjDMTS20CdCFnqTeZzBY3doP9ETaolNXKfg7LmqeD9/+mZJhzqjMiEGddFF5O Sq6y2WNF70fWXN7B9YyGzbfV5TCTCWKbf5Bp8VMifxDtgsAqavUE1yXYH5jfBYw86vWe JN7NuRwkzAABljomU5N325Vc9gbJpXmGIQGtk= Received: by 10.229.240.76 with SMTP id kz12mr6388662qcb.65.1287575937598; Wed, 20 Oct 2010 04:58:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.20.1 with HTTP; Wed, 20 Oct 2010 04:58:37 -0700 (PDT) Reply-To: RQuadling@googlemail.com Date: Wed, 20 Oct 2010 12:58:37 +0100 Message-ID: To: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Skipping of defaulted parameters. From: rquadling@gmail.com (Richard Quadling) Hello. Take the following simple code. 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. Regards, Richard. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY [1] http://docs.php.net/manual/en/language.types.null.php [2] http://docs.php.net/manual/en/functions.arguments.php#functions.arguments.by-reference [3] http://docs.php.net/manual/en/functions.arguments.php#functions.arguments.default [4] http://www.seoegghead.com/software/php-parameter-skipping-and-named-parameters.seo