As you mentioned the => syntax is already being used in PHP with associative arrays and can conflict in some places. Taking your example [$x => $x*2] this creates an array with $x doubled on index $x, while a user might want to create an array of functions.
The fn() syntax was a non-conflicting alternative, which got most support for being not too weird.
In the end it's a matter of taste and preference. There are other options as well. Each contributor (and user) certainly has a favorite and in the end it is the solutions with biggest support (and least objection)
Bike shedding can certainly be done infinitely and sometimes one has to make a choice and move on.
(I have been release manager of PHP in earlier times and helped to steer through the namespace seperator debate and did the decision to not do short array syntax, yet, but wasn't involved in the short function syntax debate)
Mixing named parameters with unnamed ones is ripe for confusion. The syntax is also going to get rather ugly now that parameters can be typed, too. If I need to pass around more than 3-4 parameters and their names/types matter a lot, I think I'll just define a class with clearly named properties and pass around an instance of it.
I'd love to have a shorter object syntax, too. For the time being, I'll make do with
My thesis was working on top of ConcreteTypeScript, which supports runtime checks https://github.com/ludamad/LocusTypeScript. My contribution was adding the ability to define types inline with code, and check those using tagging. That being said, it's all very experimental.
would like if they'd just change the syntax to foreach(something as k,v) or $arr = ['something':'value']... or then could use => ...or they could just use -> and change -> to . notation.. I use js a lot more lately so having it closer resemble es6 would make jumping back and forth easier.. I often start writing a json object when I want an associative array.
... change three different operators because you can’t handle the syntax of two different languages? Sure why not.
Perhaps php should also drop all type information so it can be more like the cluster fuck that is “modern” JavaScript too? Maybe change “const” so the constants it declares aren’t... constant?
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.
Since we are talking about new features of PHP: Does anybody else wish there were named parameters?
I think PHP is pretty complete. It is my favorite language and I don't really wish for anything added to it. Except for two things:
1: The named parameters of Python:
2: The short object Syntax of Javascript: