> As a C++ developer, I have no inherent problems with this **in
> theory**, but I agree with your statement that it's a bit symbolic
> soupish.  I also suspect that we'll run into grammar ambiguities.
> Imagine:   [ []($x) => $x ].  This is current legal syntax (at the
> point of compilation) because it *could* be interpreted as an array
> with a single element (value $x) who's key is the result of calling a
> function defined by an empty array passing a single arg ($x).  It's
> invalid at runtime (See: https://3v4l.org/IcK3B ), but that means
> special casing our way around the ambiguities.

I already mentioned the changed behavior. What you've indicated here
is not a special case of that same behavior since `[]($x)` would be
prefix to an arrow function which binds the arrow to the closure and
not the array.

> Further, if we're going to follow the C++ model, we'd be well suited
> to allow explicit per-var by-val/by-ref syntax, e.g.:
>
>   [$foo, $bar]() => $foo * $bar
>
> Again, this is legal syntax to the parser, but now it's even
> potentially current legal syntax to the runtime (assuming
> is_callable([$foo, $bar]).

You would do:

    [=, $foo, $bar]() => $foo * $bar

if you really wanted to bind everything explicitly. I haven't written
a full description in my previous thread but it's all doable except
I'd want to verify the grammar disambiguation with an empty `[]`
specifically.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to