Array variable shorthand proposal
Under discussion; proposed for PHP 8.7. The RFC page (version 1.4, dated 2026-10-03)
specifies :$name in array construction and destructuring. It stands for the explicit
key/value form "name" => $name and applies to [], array() and list(), including
destructuring in foreach.
Only a single directly named variable (T_VARIABLE) qualifies; the key is its exact,
case-sensitive name. Variable variables, array dimensions, object or static properties and
arbitrary expressions are invalid, and so is the function-argument form foo(:$name).
Whitespace and comments may appear between : and the variable. Existing keyed-element rules
still apply: duplicate keys (the later element wins, including with spread), warnings for
missing keys, and the bans on mixing list() with [] and keyed with unkeyed destructuring
elements. Construction copies the value; [:&$name] is invalid, so a reference still needs
'name' => &$name. Destructuring with an ArrayAccess object reads offsets, not properties.
The page says voting has not started. It links a draft implementation,
php-src PR #24034, which was open and marked as
a draft on 3 October.
Spelling history. Version 1.2 (2026-09-30) used =$name, after the original :$name
was dropped because of possible confusion with ternary syntax. In an internals
message on 2 October, the author announced a return to
:$name. Version 1.4 adopts it, lists the equals-sign prefix as a rejected feature, and
documents how ternaries are parsed. The conflict noted on 2 October is resolved on the RFC
page. Until a vote, the spelling can still change in discussion.
This is a proposal, not supported stable PHP syntax. Recheck the primary RFC before repeating examples or status.
Related: IO hooks proposal, type declaration milestones.