Maaz Zindani

Loading the index…

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

A Laravel or Composer command dies with a PHP parse error on a modern file

ErrorPHP Parse error: syntax error, unexpected token ")" in vendor/...

Short answer

A parse error inside vendor code almost always means the PHP that runs the command is older than the package needs, not that the file is broken. Check php -v and the PHP range of your Laravel version, then run Composer and artisan with a PHP in that range.

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

Fix it fast

  1. 1Find out which cause you have

    Find out which PHP runs the command and what Composer thinks the platform is.

    php -v
    composer check-platform-reqs
  2. 2Match what you see, then jump to its fix

    1. 1php -v prints a version below the range for your Laravel version (Laravel 12 supports PHP 8.2 to 8.5)The command-line PHP is older than the Laravel version needsFix
    2. 2The site works in the browser, but composer or artisan fails (or the reverse)Composer and the web server use different PHP versionsFix
    3. 3composer install on the server pulls packages that need a newer PHPThe lock file was built on a newer PHP than the server hasFix

What does the error look like?

  • PHP Parse error: syntax error, unexpected token ")" in vendor/...
  • composer install or php artisan stops on a parse error in a file you did not write

Cause 1 of 3

The command-line PHP is older than the Laravel version needs

1Check

Laravel's support table lists the PHP range per major version. Compare it with php -v.

php -v
grep '"laravel/framework"' composer.json

2Fix

Install and switch to a PHP version inside the range for your Laravel version, then run composer install again. If you must stay on the old PHP, stay on the Laravel major version that supports it.

composer install
php artisan --version

3Verify

artisan prints the framework version without a parse error.

php artisan --version

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

Composer and the web server use different PHP versions

1Check

Command-line and web PHP are separate installs. Compare the CLI version with the one your web server reports, and see which one Composer sees.

php -v
php -i | grep -i 'Loaded Configuration File'
composer check-platform-reqs

2Fix

Make the CLI binary point to the same PHP version as the web server, or call the right binary explicitly.

php8.3 artisan --version

3Verify

check-platform-reqs lists every requirement as success.

composer check-platform-reqs

Confirmed by getcomposer.org

Did this fix it?

Cause 3 of 3

The lock file was built on a newer PHP than the server has

1Check

Compare the PHP the lock file was created for with the server's PHP. The platform setting in composer.json fakes the PHP version so that no package needing a newer PHP can be installed.

grep -n -A3 '"platform"' composer.json

2Fix

Upgrade PHP on the server to the version the lock file needs, or set platform.php to the server's version and run composer update so the lock file picks compatible releases.

# composer.json: "config": { "platform": { "php": "8.3.0" } }
composer update

3Verify

composer install on the server now succeeds.

composer install --no-dev

Confirmed by getcomposer.org

Did this fix it?

How do I stop it coming back?

  • Pin config.platform.php to the production PHP version so a newer laptop cannot lock newer packages.
  • Run composer check-platform-reqs in CI and in the deploy script.
  • Write the supported PHP range in the README.

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.