News for hackers. Stuff that matters.
Re:25 Years of PHP [video] by FreeHugs on Sunday September 08, 2019 @04:07PM (#20913073)
I stumbled across him mentioning arrow functions comming to PHP.

Looks like this is the syntax:

    fn($x) => $x * 3
Strange that they went with fn() and not with the simpler approach established in Javascript:

    $x => $x * 3
Here is a link to see an arrow function in action:

https://3v4l.org/JpFJl

Re:25 Years of PHP [video] by bogdanu on Sunday September 08, 2019 @04:20PM (#20913156)
They chose this approach to avoid ambiquity/complexity in the parser and code readability since => is also used to declare arrays.
Re:25 Years of PHP [video] by wvenable on Sunday September 08, 2019 @04:15PM (#20913114)
Because the arrow already exists in PHP and is used for key => value mapping in arrays and foreach statements.
Re:25 Years of PHP [video] by FreeHugs on Sunday September 08, 2019 @04:19PM (#20913143)
1: But does the syntax really collide?

I would think that this:

    $a=[ 'doubler' => $x => $x*2 ]
clearly should create an array with an elemnt that is a function and has the key 'doubler'. Where is the problem?

2: And how about just using some other char combination?

    $x ~> $x * 2
Or something like that.
Re:25 Years of PHP [video] by jorams on Sunday September 08, 2019 @05:17PM (#20913471)
> But does the syntax really collide?

Yes.

    $a = [ $x => $x * 2 ];
Is this an array mapping the key $x to the value $x * 2, or is this an array mapping the key 0 to a function that doubles its input?
Re:25 Years of PHP [video] by francislavoie on Sunday September 08, 2019 @05:13PM (#20913454)
It's all covered here in the discussion section: https://wiki.php.net/rfc/arrow_functions_v2
Re:25 Years of PHP [video] by simion314 on Sunday September 08, 2019 @04:54PM (#20913345)
Isn't readability more important then typing a few less characters? We spend more time reading the code so readability is more important IMO.