“implode(): Passing glue string after array is deprecated”: the fix, and what PHP 8 does
Short answer
On PHP 7.4 it’s a deprecation notice: a plugin or theme calls implode() with the list first and the separator second, an old order PHP accepted for years. On PHP 8.0 and later that order is no longer supported and the call is a fatal error (a TypeError), so the page stops. The fix is to swap the two arguments: implode(', ', $tags). Update the plugin, or send the message to its developer.
The message, exactly
A tags plugin joins tag names with the list first. PHP 7.4 gives a notice and still joins them; PHP 8.0 stops:
wp-content/plugins/old-tags/old-tags.php
<?php
$tags = ['news', 'php', 'wordpress'];
echo implode($tags, ', '), "\n";
Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in /var/www/html/wp-content/plugins/old-tags/old-tags.php on line 3
news, php, wordpressFatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /var/www/html/wp-content/plugins/old-tags/old-tags.php:3
Stack trace:
#0 /var/www/html/wp-content/plugins/old-tags/old-tags.php(3): implode(Array, ', ')
#1 {main}
thrown in /var/www/html/wp-content/plugins/old-tags/old-tags.php on line 3php.net, for PHP 7.4: “Passing parameters to implode() in reverse order is deprecated, use implode($glue, $parts) instead of implode($parts, $glue).” (php.net) And for PHP 8.0: “Calling implode() with parameters in a reverse order ($pieces, $glue) is no longer supported.” (php.net)
Read the PHP 8 message correctly
On PHP 8 the message no longer says “swap the parameters”. It says the second argument must be a list (?array) but got text (string given): PHP takes your separator ', ' as the list. If you see that message for implode() after a PHP upgrade, the reversed order is the likely cause.
On a WordPress site this is a fatal error: “There has been a critical error on this website.” until it’s fixed or PHP is switched back.
Fix it, in order
- Site down? Switch PHP back, or pause the plugin through the link in WordPress’s email: the critical error guide.
- Find the plugin or theme: the folder after
wp-content/plugins/orwp-content/themes/in the message. - Update it (Dashboard → Updates), or send the full message to its developer: the fix is one line.
Found before you switch
The order is in the code, so a check that reads code finds it while the site still runs PHP 7.4:
More PHP 8.0 changes that stop old plugins: moving from PHP 7.4 to PHP 8.
Key takeaways
- PHP 7.4: a deprecation notice, “Swap the parameters”. PHP 8.0 and later: a fatal TypeError.
- The fix is to swap the arguments: separator first, list second.
- On PHP 8 the error reads “implode(): Argument #2 ($array) must be of type ?array, string given”.
- A check that reads code finds every call before you upgrade.
Frequently asked questions
Why does the PHP 8 error not mention the parameter order?
Because PHP 8 no longer recognises the old order at all: it reads your list as the separator and your separator as the list, and complains that the list is text.
Is join() affected too?
Yes. join() is another name for implode() and follows the same rules.
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.