Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49950 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32538 invoked from network); 21 Oct 2010 10:38:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2010 10:38:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 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.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:65074] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/9B-03733-A1810CC4 for ; Thu, 21 Oct 2010 06:38:19 -0400 Received: by qyk32 with SMTP id 32so2022527qyk.8 for ; Thu, 21 Oct 2010 03:38:16 -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 :in-reply-to:references:from:date:message-id:subject:to:cc :content-type; bh=xHLF3MD9j0ahd6/76Per+rf5Vo1uqEp/ndI32FbT9XI=; b=t0ACS/2WppdpudhwrUSosdA2VZuJyag79NBD9iCwsAF1ndEjr+occWzrUKcvx698/T Ztw7q0787TzWw3dl35IOBb/FkJNyxvCwF3PdxBky+SbecKuTjgDP7aUFW99DHhZ4laGJ K40PLwoC6lX2sT6NtpTBsRilialoM1bSbevXA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; b=Id5uMxgLdHtTFBw/DE7LGVlKIBay2eRPuUUgeOoB7ccH8YNHt0EkDaTAfqGPojXrFI MwbFDkBkrDzrhhXviBk9m/P+yDIXFFokrFbi8TW11a9pD6t92fgpcJx7rNPcIcVE78eJ Luw0lxn8nCUZO+XyIcnaGVp1O9219CgQKejZw= Received: by 10.229.75.3 with SMTP id w3mr595968qcj.296.1287657496113; Thu, 21 Oct 2010 03:38:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.20.1 with HTTP; Thu, 21 Oct 2010 03:37:55 -0700 (PDT) Reply-To: RQuadling@googlemail.com In-Reply-To: References: <988651dd53129fdfd1acb905c8161e95.squirrel@www.l-i-e.com> Date: Thu, 21 Oct 2010 11:37:55 +0100 Message-ID: To: Stan Vass Cc: Richard Lynch , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Skipping of defaulted parameters. From: rquadling@gmail.com (Richard Quadling) On 21 October 2010 09:11, Stan Vass wrote: >>> 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) >> >> It does get ugly fast for large numbers of arguments... >> But any function with more than a handful of arguments is already >> asking for trouble... >> >> At that point you should be passing in a data structure / instance / >> array or something other than so many parameters. >> > > The above example would have at least 10 arguments, so I'd also say it'd > look bad never mind the syntax. > > Also a subtle thing: if your email reader doesn't use fixed width font, it's > hard to appreciate the look of each approach in an actual code editor. > And I'd say commas next to each other appear quite readable, self-sufficient > in fixed-width font, not to mention self-explanatory. > > Using 'default' would raise more confusion, such as, is that valid: $foo = > default; bar($foo); > If it's made valid, i.e. if it acts as a constant, I suspect before long > people will be assigning 'default' as yet another alternative to a > false/null value, and we'll need yet another concept to resolve that. > If it's not made valid, it'll be counter-intuitive as it looks exactly like > a constant passed as an argument. > > Stan Vass I'm not only talking about userland code here. There are MANY functions in PHP that utilise default parameters. In most cases the lesser used parameters are at the end of the parameter list and it more often than not, it makes sense to supply the preceding parameters. Yes, I know a bunch of commas, one after the other, is unreadable. I've seen VBA code! I want null to be null. Not to be interpreted as a value. If I pass a null to a function with a default, I'm specifically NOT setting the value. Null has no value. The default is the only option that should be used. This can only apply to scalars. Objects, resources and arrays should all have the =null option. I'm guessing that the issue with implementing this in core is that each function is responsible for the defaults in such a way that they cannot easily be abstracted to the parameter processing code. The parameter values are first set to their defaults and then overwritten by the parameter processing code. I think that, for scalars, if I've supplied null, there is no value to overwrite. Take this example. This is the first function in the manual that has an optional parameter. int apc_bin_dumpfile ( array $files , array $user_vars , string $filename [, int $flags [, resource $context ]] ) Arguments that have been raised about too many parameters ... how many is too many? Is 5 OK? Why not x? $flags has no default here, but it is an int, so I have to assign something (well, I don't the default is 0 and the documentation is out on this issue, but that's another issue). So, off I go read the manual to be redirected to another page to get the list of flags I can 'OR'. But, assuming the default was documented, the prototype would look more like int $flags = 0 So, I want to use the default. OK. 0 vs null in terms of code, 0 is shorter, but it means that if the default was to change (not with this function, but any function - and that could be userland), then allowing me to say "use whatever the default is" would certainly be the way to protect me. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY