Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71098 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16567 invoked from network); 12 Jan 2014 19:35:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2014 19:35:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 198.187.29.240 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 198.187.29.240 imap2-1.ox.registrar-servers.com Received: from [198.187.29.240] ([198.187.29.240:33279] helo=imap2-1.ox.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C0/B0-13233-E6EE2D25 for ; Sun, 12 Jan 2014 14:35:12 -0500 Received: from [192.168.0.200] (unknown [176.25.177.94]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id B49F75A0051; Sun, 12 Jan 2014 14:35:07 -0500 (EST) Message-ID: <52D2EE69.9070806@ajf.me> Date: Sun, 12 Jan 2014 19:35:05 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Rowan Collins , internals@lists.php.net References: <581A185E-0F00-4B49-AA87-859D75E63BA2@googlemail.com> <52D2ED5F.4000706@gmail.com> In-Reply-To: <52D2ED5F.4000706@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Revisiting the "Named Arguments" RFC From: ajf@ajf.me (Andrea Faulds) On 12/01/14 19:30, Rowan Collins wrote: > > Personally, I'm against allowing barewords to act as strings wherever > they don't - currently - clash with keywords, for two reasons: > > Firstly, the concept in general is prone to errors in the programmer's > memory and the evolution of the language regarding which words are and > aren't allowed. One of the few differences between JSON and an actual > Javascript object declaration is that keys in JSON are *always* quoted, > and I think that was a good move on Crockford's part. People get in the > habit of using unquoted object keys in JS, and then have to dig through > the code to figure out which name some parser is choking on. > > Secondly, barewords already have a specific meaning in PHP: constants. > By convention, constants are UPPER_CASE, but the engine doesn't actually > care, and array(foo => bar) is actually valid PHP, but might be > equivalent to array('six by nine' => 42), if that's what 'foo' and 'bar' > are define()d as. > > I'm glad the introduction of shortened array syntax didn't change this > meaning, and am not convinced named parameters should either, unless the > syntax is chosen to *always* use barewords, with no variable > interpolation or ambiguity. > > As an aside, what I *would* like to see is the end of the "if a constant > isn't declared, assume it's actually a string" fallback, which feels > like a hangover from PHP's pre-history. The fact that an undeclared > class constant is a fatal error, but an undeclared global constant is a > notice is one of those inconsistencies for which PHP is notorious. > This is why I proposed earlier that we should make => in function calls work identically to array syntax, such that { const bar = "foobar"; foo(bar => 3); } would be the same as foo("bar" => 3); However, strings are quite inconvenient. So I suggest a new, bareword-only syntax, namely the colon. foo(bar: 3); would never mean the constant, and only mean the parameter named bar. We could then add this syntax to array declarations: [bar: 3, "foo" => 7] It would allow a shorter form while avoiding inconsistency with array syntax. -- Andrea Faulds http://ajf.me/