implode() fails because the glue string comes after the array
ErrorException: implode(): Passing glue string after array is deprecated. Swap the parametersShort answer
implode() takes the separator first and the array second. The old order, array first and separator second, was deprecated in PHP 7.4 and removed in PHP 8.0, where it throws a TypeError. Swap the two arguments at the call site named in the stack trace. If the call lives under vendor/, update that package.
Fix it fast
1Find out which cause you have
Open the log and read the file and line that call implode(). The path decides which cause below applies: app/, routes/ or resources/ is your code, vendor/ is a package.
grep -m1 -A8 "implode()" storage/logs/laravel.log2Match what you see, then jump to its fix
- 1
The file named in the trace is under app/, routes/, config/, database/ or resources/views/Your own code uses the old argument orderFix - 2
The trace names a file under vendor/, and the package was last released before PHP 8 came outA Composer package still uses the old orderFix - 3
The package's composer.json allows only older PHP versions, yet it installed on your PHP 8Composer was told to ignore the package's PHP requirementFix
- 1
What does the error look like?
ErrorException: implode(): Passing glue string after array is deprecated. Swap the parametersimplode(): Argument #2 ($array) must be of type ?array, string given
Cause 1 of 3
Your own code uses the old argument order
1Check
List the implode calls whose first argument is a variable, then look for a string as the second argument.
grep -rnE 'implode\([[:space:]]*\$' app routes config database resources2Fix
Put the separator first and the array second. The one-argument form, implode($array), is still valid and joins with an empty string.
// before: array first, separator second
$tags = implode($names, ', ');
// after: separator first
$tags = implode(', ', $names);3Verify
Repeat the request or command that failed. The call returns the joined string and no new entry appears in the log.
tail -n 20 storage/logs/laravel.logConfirmed by php.net
Cause 2 of 3
A Composer package still uses the old order
1Check
Find which package owns the file, then compare its installed version with what its maintainers have released. A release that supports PHP 8 has the call swapped.
composer show vendor/package2Fix
Update that package, and its dependencies if the update needs them. If no release works on your PHP version, replace the package. Do not make an edit under vendor/ your fix: a fresh install or a package update discards it.
composer update vendor/package --with-dependencies3Verify
The installed version is newer, and the same page or command runs clean.
composer show vendor/packageConfirmed by getcomposer.org
Cause 3 of 3
Composer was told to ignore the package's PHP requirement
1Check
--ignore-platform-reqs makes Composer install packages even when your PHP does not meet their requirements, which hides an old package behind a clean install. check-platform-reqs reports installed packages whose PHP or extension requirements do not match the PHP you run.
composer check-platform-reqs
grep -rn "ignore-platform" composer.json Dockerfile2Fix
Remove the flag from your install command, then update or replace each package the check reports.
composer install --no-dev
composer check-platform-reqs3Verify
check-platform-reqs reports only matching requirements.
composer check-platform-reqsConfirmed by getcomposer.org
How do I stop it coming back?
- Run composer check-platform-reqs in CI on the same PHP version you deploy.
- Never put --ignore-platform-reqs in a deploy script.
- Write implode(', ', $array) every time, so the order cannot drift between old and new code.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
PHP says Array to string conversion and prints the word Array
Notice: Array to string conversion (PHP 7)
PHP turns any array used as a string into the text Array and, since PHP 8.0, raises a warning.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fix