rfc:deprecate_curly_braces_array_access
This is an old revision of the document!
PHP RFC: Deprecate curly braces syntax for accessing array element and string offset.
- Version: 0.9
- Date: 2019-03-12
- Author: Andrey Gromov, andrewgrom@rambler.ru
- Status: Under Discussion
- First Published at: https://wiki.php.net/rfc/deprecate_curly_braces_array_access?do=edit
- Discussion: https://externals.io/message/104744
Introduction
Both square brackets and curly braces can be used interchangeably for accessing array elements (e.g. $array[42] and $array{42} will both do the same thing in the example above).
Proposal
Deprecate curly braces syntax for accessing array element and string offset.
Reasons to deprecate curly braces syntax::
- Two ways to do the same thing.
- It is very rarely used nowadays.
- It is almost not documented. There is only two short “NOTE” about it.
- Also, this syntax has reduced functionality. You can't use it for pushing element into array “$arr{} = 1;”, creating array “$a={1,2};” or in other similar cases.
- Deprecation and following removal will free this syntax for other features. For example: array/string slice, absolute offset access, “windows” (like “slice” in GoLang), etc.
<?php $arr=[1,2,3]; var_dump($arr{1});
Output
Warning: Array and string offset access syntax with curly braces is deprecated in /root/php-src/1.php on line 4 int(2)
Backward Incompatible Changes
Yes.
Proposed PHP Version(s)
PHP 7.4
Future Scope
Change to E_COMPILE_ERROR in PHP 8.0. Remove in PHP 8.1.
Voting
2/3 majority will be required.
Patches and Tests
rfc/deprecate_curly_braces_array_access.1552810484.txt.gz · Last modified: 2019/03/17 08:14 by rjhdby