Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60215 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3994 invoked from network); 19 Apr 2012 10:38:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2012 10:38:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=patrick.allaert@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.170 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 209.85.210.170 mail-iy0-f170.google.com Received: from [209.85.210.170] ([209.85.210.170:36405] helo=mail-iy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/31-29087-71BEF8F4 for ; Thu, 19 Apr 2012 06:38:15 -0400 Received: by iaeh11 with SMTP id h11so13897747iae.29 for ; Thu, 19 Apr 2012 03:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=KXy8osPjok2EfGhcSaa96yMUG+YRu09igzIPiBSIZ7A=; b=QowYDylTBGXuGj8IZL/gBZl/2bjOYQXdtzw6BV+TRsBLy2Tu6GId753YLlIrsiWR8n yiggjWdZ0GcN3JjHdeLiNbCm3maL+XQwMnHCwBB6dSDY8FhnGtPQQxrWLaG0iErMwuOH EaFfYJTZJg78vGVxegyHpbGTQHumvyaxMSOQB2IuvufEXiK0rutoi4gHn20kYE/nOTKs zfxp+sD5K+89mfXaaiTpOLxn1cqGxYadpt5AT1Yi2aOBmqWwR3U7VPjnMNY7O+wT7pwd 0C3Ri5MJEoAwX3V4e67iNP11c2/G76VJM0a7ddCd7VJKF7JBUomPvajem3+gBXU+Y1sm 59tg== MIME-Version: 1.0 Received: by 10.50.76.136 with SMTP id k8mr709026igw.2.1334831892404; Thu, 19 Apr 2012 03:38:12 -0700 (PDT) Sender: patrick.allaert@gmail.com Received: by 10.231.229.196 with HTTP; Thu, 19 Apr 2012 03:38:12 -0700 (PDT) In-Reply-To: References: <4F8DF4B1.2040307@sugarcrm.com> Date: Thu, 19 Apr 2012 12:38:12 +0200 X-Google-Sender-Auth: cMSArapgpBhdQVMIrel3qhzHI74 Message-ID: To: "Matthew Weier O'Phinney" , Stanislav Malyshev Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: [RFC] skipping optional parameters From: patrickallaert@php.net (Patrick ALLAERT) 2012/4/18 Matthew Weier O'Phinney : > My one comment, which others have raised, is readability of multiple > commas -- TBH, at first glance it has the appearance of a mistake. I > think those suggesting a keyword such as "default" make a good point in > this regard -- it makes it 100% clear that you want the default value > for the argument in that position. This also presents an improvement > over current usage, as you're not hard-coding values in your function > calls themselves -- particularly as the defaults could change in future > refactors. I think we should only support optional parameters using the "default" keyword as it would probably make things more consistent and less error prone: function foo( $bar = "bar", $foo = "foo", $baz = "baz" ) { ... } foo(,,, "myBaz"); // Thinking changing the value of $baz, but there's one too much "," and PHP won't complain because of too many arguments used! Additionally, we might also want to think about call_user_func()/call_user_func_array(). If for the former it could work with: call_user_func( "foo", , , "myBaz" ); What about the latter? call_user_func_array( "foo", [2 => "myBaz"] ); // ? Evaluating the element at index 0 would cause a notice, but would result in a NULL, so I would say that NULL is to be used as first parameter. I have no clue on how to correctly support skipped default values in that case since there is a big difference in supporting the "default" keyword inside the method call vs. as an element of an array. Ideas are welcome! Last but not least: if skipping optional parameters is implemented, should we consider the support of default values on the leftmost side of functions? function foo( $bar = "bar", $baz ) { ... } It could make sense that $bar followed by $baz is semantically better than the opposite for technical reason, and this could be called using: foo( default, "baz") or: foo(, "baz")