Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25909 invoked from network); 12 Jan 2014 21:07:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2014 21:07:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=ingwie2000@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ingwie2000@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.215.177 as permitted sender) X-PHP-List-Original-Sender: ingwie2000@googlemail.com X-Host-Fingerprint: 209.85.215.177 mail-ea0-f177.google.com Received: from [209.85.215.177] ([209.85.215.177:65141] helo=mail-ea0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/62-13233-82403D25 for ; Sun, 12 Jan 2014 16:07:53 -0500 Received: by mail-ea0-f177.google.com with SMTP id n15so2928650ead.22 for ; Sun, 12 Jan 2014 13:07:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=GfWMmTChJuMykA1JSlVh7Rd6qe/RBm5MonGej52rwsc=; b=IWdcqxtBLLqP3B5e6CqOLbbv9hjc42qjz2CK8Ntg3IOH6VQj8QoYpHTf0iPrWESWIK Eg+RoIjOv0CXWdVZxtB+b2E3qz5cRsZWpnD4Rb2lgSOafhVz2vNmwOLvAMpTlcDPUEx1 Qd244EWxfhw+jX9kWwcMtb9ogzF9kNojx4GVY4QZyeOAX9NhUrhwDiH9AJGl2Tv3n7xp Rk/esMxA6pHKnvqYPQ9BdixUXhZedxaLojYmYri3RVzSzrE6dfHPUwshNNjIBzljFYKH /ovCGl20QdwffVw0X8uvbFmJp1VmhZZUpjc4BMOsl0c+um1+J7F9RNLkUyhvaU1T/WdL O74A== X-Received: by 10.15.22.137 with SMTP id f9mr23536744eeu.30.1389560867893; Sun, 12 Jan 2014 13:07:47 -0800 (PST) Received: from [192.168.200.19] (dslb-088-069-033-242.pools.arcor-ip.net. [88.69.33.242]) by mx.google.com with ESMTPSA id l41sm30540543eep.17.2014.01.12.13.07.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 12 Jan 2014 13:07:47 -0800 (PST) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) In-Reply-To: <52D301F3.9010600@gmail.com> Date: Sun, 12 Jan 2014 22:07:46 +0100 Cc: Andrea Faulds , internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <581A185E-0F00-4B49-AA87-859D75E63BA2@googlemail.com> <52D2ED5F.4000706@gmail.com> <52D2EE69.9070806@ajf.me> <52D301F3.9010600@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1822) Subject: Re: [PHP-DEV] Revisiting the "Named Arguments" RFC From: ingwie2000@googlemail.com (Kevin Ingwersen) The parser would have to be taught an actual, pretty simple, condition: = Perform unusual parsing between parantheses. In pseudo code, that=92d = be: if(in function argument list) if(has named parameters) obtain, assign and pass the paraneters. else fall back to traditional positioned parameters. It would also have to ignore keywords. But that means that it would have = to temporarily swap T_CONSTANTS for anything that is left from the = colon. OR the colon must be attached to the last character. I.e.: copy(from: $file, to: $file); // valid. copy(from : $file, to : $file); // may thro an error for = undefined constant? So if the parser knows when to =84think different=93, then I doubt that = it=92ll be showing off un-robustness. However, what if the closing = paranthese is missing? That are things that concern me now - actual = syntax errors. Am So. Jan. 12 2014 21:58:27 schrieb Rowan Collins: > On 12/01/2014 19:35, Andrea Faulds wrote: >>=20 >> This is why I proposed earlier that we should make =3D> in function = calls work identically to array syntax, such that { const bar =3D = "foobar"; foo(bar =3D> 3); } would be the same as foo("bar" =3D> 3); >>=20 >> 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" =3D> 7] >>=20 >> It would allow a shorter form while avoiding inconsistency with array = syntax.=20 >=20 > The question, is, is the parser robust enough to guarantee that the = following will all be parsed correctly: >=20 > do_soap_call(namespace: 'foo'); > check(if: $arriving =3D=3D=3D true, true: 'Hello', false: 'Goodbye'); > $callback =3D array( function: function() { }, array: array( ) ); >=20 > I can't think of a case off the top of my head where it would be = *theoretically* impossible, but that doesn't mean it would be trivial to = implement, and if there were any cases where it couldn't be used, I'd = personally much rather it didn't exist at all. (And what about secondary = parsers, e.g. syntax highlighters?) >=20 > I'm also not convinced that it's something worth having more than one = way to write, as it just makes code harder to read for new coders: will = it be obvious that [bar: 3] is the same as ['bar' =3D> 3], but not the = same as [bar =3D> 3], except when it is, because of "undefined constant, = assumed string" fallbacks...? >=20 > I think I'd personally lean towards using a $ to mark named = parameters, and simply not allow dynamically choosing which parameter = gets passed (that strays close to "variable variable" territory anyway, = of which I'm not a fan). If I think of the function signature "function = foo($bar) { ... }", I would tend to think of the argument as "$foo" not = "foo" anyway, so it doesn't seem a stretch that "foo($bar =3D> 3);" = would mean "call function foo(), with argument $bar set to 3". >=20 > Regards,