Andrea Faulds


PHP RFC: Bare Name Array Dereference


The current array dereferencing syntax for string keys is somewhat cumbersome:


To dereference an array with a string key requires four characters. By contrast, dereferencing objects is much shorter, as the key name does not need to be quoted most of the time:


That requires just two characters. So, this RFC proposes a similar syntax for dereferencing string keys fitting the IS_STRING profile:


The :> syntax is just my initial proposal. If there is a better (less ugly?) alternative token, please suggest it.

This complements the Bare Name Array Literal RFC, as both this proposal and that one deal with using bare T_STRING names for array keys.


Along with the existing syntax for dereferencing a key in an array, the following new syntax is added:

  array :> T_STRING

This functions the same as dereferencing a quoted key in square brackets.

Backward Incompatible Changes

None. This has no effect on existing code.

Proposed PHP Version(s)

Proposed for the next PHP 5.x, which at the time of writing, is PHP 5.7.

RFC Impact

SAPIs, extensions, opcache, constants and php.ini are unaffected. No new opcodes are added, this is purely a parsing change.

Open Issues

The :> syntax might not be ideal, and I'm willing to take suggestions for better syntax.

Unaffected PHP Functionality

$arr:>foobar are the same $arr['foobar'], so it is completely optional and shouldn't break anything.

Future Scope

None I can see.

Patches and Tests

There is a working and tested patch implementing this here: https://github.com/TazeTSchnitzel/php-src/compare/bareNameArrayDereference

The branch on my GitHub account is here: https://github.com/TazeTSchnitzel/php-src/tree/bareNameArrayDereference


If/when the RFC is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature


Rejected Features

None as yet.


An option needs 2/3 votes to win

Merge array dereference into master/PHP 5.7? (0% approved)
User Vote
aharvey No
arpad No
brianlmoon No
bwoebi No
colder No
datibbaw No
derick No
fa No
levim No
malukenho No
mbeccati No
rasmus No
stas No
tyrael No
zeev No