Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

implode() fails because the glue string comes after the array

ErrorErrorException: implode(): Passing glue string after array is deprecated. Swap the parameters

Short 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.

  • Applies to PHP 8.3, Laravel 12, Composer 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.log
  2. 2Match what you see, then jump to its fix

    1. 1The file named in the trace is under app/, routes/, config/, database/ or resources/views/Your own code uses the old argument orderFix
    2. 2The 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. 3The 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

What does the error look like?

  • ErrorException: implode(): Passing glue string after array is deprecated. Swap the parameters
  • implode(): 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 resources

2Fix

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.log

Confirmed by php.net

Did this fix it?

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/package

2Fix

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-dependencies

3Verify

The installed version is newer, and the same page or command runs clean.

composer show vendor/package

Confirmed by getcomposer.org

Did this fix it?

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 Dockerfile

2Fix

Remove the flag from your install command, then update or replace each package the check reports.

composer install --no-dev
composer check-platform-reqs

3Verify

check-platform-reqs reports only matching requirements.

composer check-platform-reqs

Confirmed by getcomposer.org

Did this fix it?

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

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.