Hello,

On Tue, Feb 19, 2013 at 6:09 PM, Levi Morrison <morrison.l...@gmail.com> wrote:
> There's already been an overwhelming negative reaction to this
> particular proposed syntax so I won't belabor the point much.  In
> short, this is too similar to block statements and does have BC
> issues.
>
> --
>
> IF (and I stress if) we add a a shorter anonymous function syntax I'd
> like it to be geared towards one-liners because that's where the
> current syntax feels really verbose, especially when you close over
> other variables:
>
>     function ($n) use ($m) { return $m * $n; }
>
> Versus one potential option:
>
>     ($value) |$m| => $m * $n;
>
> This syntax is short and expressive at the expense of clarity.
> Basically all short-syntax has that trade-off, so I am personally fine
> with it. The only other potential problem I see is parsing it; someone
> more familiar with PHP's parser would have to verify whether that
> would be a problem.
>

I think that before we establish a syntax for this we should see if there's
a real need for this feature, and after that, get a syntax to implement the
feature.

Say we agree on the syntax above
> ($n) |$m| => $m * $n;
What happens when my one liner function needs to do one more operation
like checking the value of $n before multiplication?

I'd rather see a proposal to drop the 'function' keyword from the classes
methods and only leave the visibility scope and method name, but for
anonymous functions like this one I'd rather keep the 'function' keyword in
order to have better visibility when I'm doing a code review/scan new code
in a library.

What do you think?

----
Florin Patan
https://github.com/dlsniper

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

Reply via email to