A Laravel or Composer command dies with a PHP parse error on a modern file
PHP 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.
Fix it fast
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-reqs2Match what you see, then jump to its fix
- 1
php -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
The site works in the browser, but composer or artisan fails (or the reverse)Composer and the web server use different PHP versionsFix - 3
composer install on the server pulls packages that need a newer PHPThe lock file was built on a newer PHP than the server hasFix
- 1
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.json2Fix
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 --version3Verify
artisan prints the framework version without a parse error.
php artisan --versionConfirmed by laravel.com
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-reqs2Fix
Make the CLI binary point to the same PHP version as the web server, or call the right binary explicitly.
php8.3 artisan --version3Verify
check-platform-reqs lists every requirement as success.
composer check-platform-reqsConfirmed by getcomposer.org
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.json2Fix
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 update3Verify
composer install on the server now succeeds.
composer install --no-devConfirmed by getcomposer.org
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 says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fixBack end
PHP says unexpected token '?' on code that looks correct
Syntax error: unexpected token '?' PHP(PHP2014)
The code is valid, but the PHP that parses it is too old.
4 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 fix