Array and String Offset Access with Curly Braces Has Been Removed in PHP 8.0

Array and String Offset Access with Curly Braces Has Been Removed in PHP 8.0

Array elements and string offsets can be accessed using square bracket [] syntax. There is also curly brace {} syntax, which is rarely used in practice. Since PHP 7.4, curly brace syntax for accessing array elements and string offsets has been deprecated and since PHP 8.0 this syntax has been removed.

Let's say we have a code that uses curly brace syntax:

<?php

$array = [10, 20, 30, 40];
echo $array{0};

$str = 'Hello';
echo $str{0};

A code can be rewritten using square bracket syntax as follows:

<?php

$array = [10, 20, 30, 40];
echo $array[0];

$str = 'Hello';
echo $str[0];

Leave a Comment

Cancel reply

Your email address will not be published.