rfc:deprecate_curly_braces_array_access

This is an old revision of the document!


PHP RFC: Deprecate curly braces syntax for accessing array element or string offset.

This is a suggested template for PHP Request for Comments (RFCs). Change this template to suit your RFC. Not all RFCs need to be tightly specified. Not all RFCs need all the sections below. Read https://wiki.php.net/rfc/howto carefully!

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::

  1. Two ways to do the same thing.
  2. It is very rarely used nowadays.
  3. It is almost not documented. There is only two short “NOTE” about it.
  4. 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.
  5. 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.1552810171.txt.gz · Last modified: 2019/03/17 08:09 by rjhdby