On Fri, Mar 15, 2019 at 2:39 PM Andrey O Gromov <agro...@alfabank.ru> wrote:
> 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. > > Proposal > https://wiki.php.net/rfc/deprecate_curly_braces_array_access > > Patch diff > > https://github.com/php/php-src/compare/PHP-7.4...rjhdby:deprecate_alternate_array_access > > Migration script > > https://github.com/rjhdby/php-src/blob/deprecate_alternate_array_access/convert_array_access_braces.php I'm okay with this. This syntax has already been deprecated once, though it was reverted for reasons I don't remember. There are some people using this syntax to distinguish between array and string access. It's a nice thought, but as the vast majority of code doesn't make this distinction (I think the only time I saw this in recent years was inside some old PEAR code), it's not really a useful indicator. The rarity of its use also makes it rather confusing. While $foo[$x] is well established as an array or string offset (or for that matter, ArrayObject) access and will be recognized by any programmer coming from any number of programming languages, $foo{$x} certainly is not, and is a WTF moment for people who don't happen to personally use this syntax. I'd prefer to phase out this syntax entirely and not reuse it for any other purpose. Reusing syntax is generally a not so good idea, because it means that the same syntax has different meaning in different PHP version. Nikita