Hacker News new | ask | show | jobs
by Freegile 2399 days ago
But does it have to be =>? How about ~>?

    $a=[$x ~> $x*2, $x ~> $x*$x];
    $a[1](5); // 25
Looks cool to me.
2 comments

~ is annoying to type on some keyboard layouts (Alt Gr and + onna German keyboard)

Also PHP tries to be "googlable". Typing "fn PHP" into Google should bring relevant hits, for people never seen such a construct.

> Also PHP tries to be "googlable".

If not insisting on the "google" part, there always is http://symbolhound.com/?q=php+%7E%3E

I noticed lately google is starting to understand symbols in certain contexts. Searching "php =>" actually does provide relevant results.
There's some rationale here[0]. Basically they'd need to use a parser that on ambiguities would have to go down all possible routes concurrently until all but one fail, which can lead to performance costs. Using a prefix keeps things simple.

[0] https://wiki.php.net/rfc/arrow_functions_v2#x_x_y1