Array and string offset access syntax with curly braces is no longer supported

Description

PHP used to support the curly braces {} to access elements in an array and a string. This was deprecated in PHP 7.4 and abandonned in PHP 8.0. The only operator to access an element is the square brackets [].

Example

<?php

$string = 'abc';
echo $string{1}; // b

$array = ['A', 'B', 'C'];
echo $array{1};  // B


?>

Solutions

  • Switch to the square brackets.

  • Use the substr() function to extract one string char.

In previous PHP versions, this error message used to be Array and string offset access syntax with curly braces is deprecated.