A new Array Variable Shorthand RFC proposes writing [=$name] instead of ['name' => $name] in PHP 8.7. Weilin Du opened the discussion on internals on September 29, and the thread ran to about ten messages in its first day, from a +1 to a promised no vote.
If you build arrays from local variables with the same names, or pull values back out of them, you've typed every key twice. The RFC takes the key from the variable's name instead.
What It Does
An element written =$name means the same as 'name' => $name. It works when you build an array and when you destructure one:
$x = 10; $y = 20; $point = [=$x, =$y]; // ['x' => 10, 'y' => 20] [=$x, =$y] = $point; // $x = 10, $y = 20
You can mix it with regular keys, and it works in foreach, array() and list() too:
$user = ['id' => 1, =$name, =$age]; [=$name, 'age' => $years] = $user; foreach ($rows as [=$name]) { echo $name; }
It only takes a plain variable. =$object->name, =$name[0] and =$$name are all invalid, and so is =&$name, so references still need the explicit key. The key is the variable name exactly as written, so $Name and $name give two different keys. The RFC doesn't add the same shorthand for function arguments.
The first version used :$name. Weilin switched to = within hours, after a discussion on the PHP community Discord, because : already has a job inside arrays as part of the ternary operator: [$condition ? 'bar' :$baz] is valid PHP today.
The Pushback
Sebastian Bergmann replied that he doesn't accept the premise and will vote against it:
A syntax change should be backed by data, for instance an analysis of a representative body of real-world code.
David Carlier raised a readability problem with =. A single missing comma turns one valid line into another that means something different:
$b = 5; $arr = [$a =$b]; // today: assigns 5 to $a, $arr is [0 => 5] $arr = [$a, =$b]; // with the RFC: $arr is [0 => $a, 'b' => 5]
Anton Smirnov pointed out that compact() and extract() already cover the idea. Weilin answered that they can't be mixed with explicit keys, can't pick which variables get written, and don't work in a foreach destructure.
Alexander Egorov said the feature would win him over if it also took properties, like [=$this->id, =$this->name], for turning DTOs into arrays. Lynn asked whether => $x could work as the prefix instead.
Christian Schneider was in favor, and said his team has run a local patch for this syntax for years. He'd still rather have the original :.
Where It Stands
The RFC is at version 1.2 and targets PHP 8.7. I personally like the idea of this RFC but until it goes to vote we will not know if this will actually be approved. You can follow its status on our RFC tracker, or read the full proposal and examples in the RFC on the PHP wiki.