“Array and string offset access syntax with curly braces is no longer supported”: fixing old WordPress code
Short answer
It’s a fatal error from PHP 8.0 and later: a plugin or theme reads one letter of a text, or one entry of a list, with curly braces ($code{0}) instead of square brackets ($code[0]). PHP 7.4 showed a deprecation notice; PHP 8.0 can’t read the file at all, so everything in it stops, even code that never reaches that line. Update the plugin or theme. A check that reads code finds it before you switch.
The message, exactly
An old shortcode plugin reads the first letter of a code with curly braces. PHP 7.4 runs it with a deprecation notice; PHP 8.0 stops:
wp-content/plugins/old-shortcodes/old-shortcodes.php
<?php
$code = 'ABC123';
echo 'First letter: ', $code{0}, "\n";
Deprecated: Array and string offset access syntax with curly braces is deprecated in /var/www/html/wp-content/plugins/old-shortcodes/old-shortcodes.php on line 3
First letter: AFatal error: Array and string offset access syntax with curly braces is no longer supported in /var/www/html/wp-content/plugins/old-shortcodes/old-shortcodes.php on line 3The 7.4 notice already announced it. php.net, for PHP 7.4: “The array and string offset access syntax using curly braces is deprecated. Use $var[$idx] instead of $var{$idx}.” (php.net) And for PHP 8.0: “Support for deprecated curly braces for offset access has been removed” (php.net).
Why the whole file stops
Compare the two outputs above. PHP 7.4 shows the notice and still prints the first letter. PHP 8.0 prints nothing at all, not even “First letter:”, which comes before the braces on the same line: it never started running the file. PHP reads a file completely before it runs it, and on PHP 8.0 it can’t read this one. Everything the file defines (functions, classes, hooks) is missing, which is why one forgotten pair of braces can take down a whole plugin, or the whole site when the file is loaded on every page.
On a WordPress site you see “There has been a critical error on this website.” and the administrator gets an email with the details.
Find the plugin or theme
The path in the message names it: the folder after wp-content/plugins/ or wp-content/themes/, here old-shortcodes. The file and line are for whoever fixes it.
Fix it, in order
- Site down? Switch PHP back in your hosting panel first, or use the link in WordPress’s email to pause the plugin. The critical error guide shows both.
- Update the plugin or theme (Dashboard → Updates).
- Already on the latest version? Send the full message to its developer: the fix is quick for them.
- Not maintained any more? Replace it. Code that still has this syntax hasn’t been updated for PHP 8 and is likely to have other PHP 8 problems.
Found before you switch
Because the syntax is in the code itself, a check that reads code finds every occurrence while your site still runs PHP 7.4:
CompatNav reports it as code the new PHP version can’t load, with the file and line. Other PHP 8.0 removals behave the same way: each() and create_function() are the ones you’re most likely to meet next to it. The full list of what changed with PHP 8.0 is in moving from PHP 7.4 to PHP 8.
Key takeaways
- Curly braces for offset access (
$text{0}) were deprecated in PHP 7.4 and removed in PHP 8.0. - On PHP 8.0 and later it’s a fatal error when the file loads: the whole file fails, not just the line.
- The fix is one character each side:
$text{0}becomes$text[0]; it works on every PHP version. - Find the plugin from the path in the message, then update it or send the message to its developer.
- A check that reads code finds every one before you upgrade.
Frequently asked questions
Why does the whole plugin stop, not just one feature?
PHP reads a whole file before running any of it. On PHP 8.0 it can’t read a file with this syntax, so nothing in that file runs, whichever line has the braces.
Can I fix it myself?
The change is small, but edits to a plugin’s files are lost with its next update, and a typo breaks the site. Update the plugin, or ask its developer; if it’s no longer maintained, replace it.
My site showed a notice about curly braces before. Is that the same thing?
Yes. PHP 7.4 showed “Array and string offset access syntax with curly braces is deprecated”. That was the warning; on PHP 8.0 the same code no longer loads.
Check your own site before you upgrade
CompatNav is a free WordPress plugin. It reads the code of your plugins and themes on your own server and tells you, in plain words, what will break and what will only show notices on the PHP version you choose. It never changes your code. It can’t see problems that only appear while code runs with real data, so a quick check of your site after the upgrade still matters.
Sources
About the code examples: each output is the real output of the code shown, run with the official PHP builds, without a php.ini, with all errors reported and displayed. Only the file path was replaced by a neutral server path.