PHP 8 no longer accepts curly braces for string or array offsets. Code such as $color{0} produces a syntax error. Replace that syntax with square brackets, then confirm whether the original code intended to read a byte, a text character, or an array element.
Last updated: November 12, 2026.
<?php
$hex = '3A7FCC';
$red = hexdec($hex[0] . $hex[1]);
$green = hexdec($hex[2] . $hex[3]);
$blue = hexdec($hex[4] . $hex[5]);
printf("rgb(%d, %d, %d)
", $red, $green, $blue);
$settings = ['theme' => 'dark'];
echo $settings['theme'];Square brackets work for both string offsets and array keys. They are compatible with maintained PHP releases and make the intended offset operation explicit.
Make the mechanical replacement carefully
The PHP 8 migration guide confirms that curly-brace offset access was removed. Convert $value{$index} to $value[$index] and $array{"key"} to $array["key"]. Do not replace braces used for blocks, variable interpolation, object access, or class syntax.
Run the project’s tests and search the complete codebase, including templates and generated files. A syntax error prevents PHP from loading the file, so a runtime compatibility shim cannot rescue the old expression.
Distinguish bytes from characters
The PHP string documentation explains that bracket offsets operate on bytes. That is correct for ASCII hex values, protocol bytes, and other single-byte data. It is not a safe way to select a Unicode character from UTF-8 text, where one character may occupy several bytes.
For user-facing UTF-8 text, use an appropriate multibyte function such as mb_substr($text, $index, 1, "UTF-8") and define behavior for invalid input. Also check bounds: reading an unavailable string offset raises a warning, and illegal offset types can throw TypeError on current PHP. The syntax replacement fixes parsing, but tests must confirm the original data assumptions.