Last updated: November 25, 2026.
Replace $value{0} with $value[0] when old PHP code uses braces to read an offset. PHP 8 removed that offset syntax for strings and arrays. In a hexadecimal color parser, each square-bracket offset still reads one byte.
<?php
function parseRgb(string $color): array
{
if (preg_match('/^#?[0-9a-f]{6}$/iD', $color) !== 1) {
throw new InvalidArgumentException('Expected a six-digit hex color.');
}
$hex = ltrim($color, '#');
return [
'red' => hexdec($hex[0] . $hex[1]),
'green' => hexdec($hex[2] . $hex[3]),
'blue' => hexdec($hex[4] . $hex[5]),
];
}
print_r(parseRgb('#3B82F6')); // red 59, green 130, blue 246Change the offset expression
Keep the expression inside the brackets. For example, $value{$index + 1} becomes $value[$index + 1]. The same migration applies to array keys, such as reading the name entry of an associative array.
Review each match before editing a directory of source files. Braces also delimit code blocks, interpolation and other valid syntax. In a double-quoted string, "{$name}" uses braces around a variable for interpolation and can stay as written.
Check what an offset reads
PHP string offsets count bytes starting at zero. That works for hexadecimal colors because every allowed digit occupies one byte. Validate the input before reading offsets so malformed or short strings do not produce undefined-offset warnings. The example accepts six digits with an optional leading hash.
For text that can hold multiple bytes per character, such as UTF-8 labels, choose a character-aware operation appropriate to the text rather than assuming an offset points to a full character. Lint the modified file, then run the affected routine with ordinary and invalid input to verify its behavior.