“Unparenthesized a ? b : c ? d : e is not supported” in WordPress: the fix

By CompatNav · Published · Last reviewed · 3 min read

Short answer

It’s a fatal error from PHP 8.0 and later: a plugin or theme chains two ? : choices without brackets, which PHP 7.4 deprecated and PHP 8.0 refuses. PHP can’t load the file at all, so everything in it stops and WordPress shows “There has been a critical error on this website”. Old code like this often gave the wrong answer anyway, because PHP read it in an unexpected order. Update the plugin or theme; a check that reads code finds it before you switch.

The message, exactly

An old gallery plugin picks a label with two chained choices. PHP 7.4 shows a deprecation notice; PHP 8.0 can’t load the file:

wp-content/plugins/old-gallery/old-gallery.php

<?php
$count = 0;
$label = $count == 0 ? 'no photos' : $count == 1 ? 'one photo' : 'photos';
echo $label, "\n";

Output on PHP 7.4.33

Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/html/wp-content/plugins/old-gallery/old-gallery.php on line 3
one photo

Output on PHP 8.0.30the script stopped

Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /var/www/html/wp-content/plugins/old-gallery/old-gallery.php on line 3

php.net, for PHP 7.4: “Nested ternary operations must explicitly use parentheses to dictate the order of the operations. Previously, when used without parentheses, the left-associativity would not result in the expected behaviour in most cases.” (php.net)

The old code was often wrong anyway

Look at the PHP 7.4 output above: with no photos at all, the label says “one photo”. “Left-associativity” means PHP 7 grouped the chain from the left, while most people read it from the right. Another example, with both readings written out in brackets, on PHP 7.4:

wp-content/plugins/old-badges/old-badges.php

<?php
$level = 1;
echo ($level == 1 ? 'bronze' : $level == 2) ? 'silver' : 'gold', "\n";
echo $level == 1 ? 'bronze' : ($level == 2 ? 'silver' : 'gold'), "\n";

Output on PHP 7.4.33

silver
bronze

The first line is how PHP 7 read the chain: for level 1 it answers “silver”. The second is what the author almost certainly meant: “bronze”. So a site that “worked” on PHP 7 may have shown the wrong label for years. That is why PHP 8.0 refuses to guess, and why fixing it needs someone who knows what the code should do.

Fix it, in order

  1. Site down? Switch PHP back in your hosting panel, or pause the plugin through the link in WordPress’s email. The critical error guide shows both.
  2. Find the plugin or theme: the folder after wp-content/plugins/ or wp-content/themes/ in the message.
  3. Update it (Dashboard → Updates).
  4. Already on the latest version? Send the full message to its developer. If nobody maintains it, replace it: code with this syntax hasn’t been updated for PHP 8.

Found before you switch

The syntax is in the code itself, so a check that reads code finds every one while your site still runs PHP 7.4:

The same kind of problem, syntax PHP 8.0 can’t read, is curly-brace offsets; the full PHP 8.0 list is in moving from PHP 7.4 to PHP 8.

Key takeaways

  • Nested ? : without brackets was deprecated in PHP 7.4 and is a fatal error from PHP 8.0.
  • PHP refuses the whole file when it loads, not just the line.
  • PHP 7 read such chains from the left, which rarely meant what the author intended: the old code was often quietly wrong.
  • The fix is brackets that say which choice comes first; the developer decides which order was meant.
  • A check that reads code finds every one before you upgrade.

Frequently asked questions

Why does the whole plugin stop?

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, wherever the line is.

Can I just add brackets myself?

Not safely: where the brackets go changes the result, and only someone who knows what the code should do can choose. Edits to a plugin’s files are also lost with its next update. Update the plugin, or ask its developer.

Is it the same problem as curly-brace offsets?

The same kind: syntax PHP 7.4 deprecated and PHP 8.0 can’t read, so the whole file fails. Both are found by a check that reads code.

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.

Get CompatNav on wordpress.org How it works

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.