What the message looks like
PHP Parse error: syntax error, unexpected token ";" in /var/www/html/wp-content/plugins/x/functions.php on line 214Common causes
- Syntax removed in PHP 8: string offsets with curly braces
$str{0},create_functionor other old constructs. - The file is half uploaded or truncated, for example after an interrupted FTP or deploy.
- A semicolon, brace or quote is missing in the line before.
- Invisible characters from the editor: a BOM at the start of the file or non-breaking spaces.
- A plugin is parsed by a newer PHP version than it supports.
Check
- Lint the reported file
php -l /var/www/html/wp-content/plugins/x/functions.php - PHP version and recent errors
php -v; tail -n 20 /var/log/php8.2-fpm.log - Find old string offset syntax
grep -rnE '\$[a-zA-Z_]+\{[0-9]+\}' /var/www/html --include='*.php' | head - Find BOM and non-breaking spaces
grep -rlP '^\xEF\xBB\xBF' /var/www/html --include='*.php' | head
Fix
- Run
php -lon the reported file first: the line in the log is often not the real cause. - When moving to PHP 8, replace removed syntax:
$str{0}becomes$str[0],create_functionbecomes a closure. - Re-upload truncated files or replay the update if the upload was incomplete.
- Remove BOM and non-breaking spaces and save the file as UTF-8 without BOM.
- Clear the opcache afterwards, otherwise the old broken version keeps running.
Typical scenario
A Composer package with PHP 8 syntax (match, ?->) is deployed, but PHP-FPM still runs on 7.4, while php -v in the console says 8.2. The FPM log shows PHP Parse error: syntax error, unexpected token "=>". A php -l in the console wrongly reports no error because it uses the other version. First check which PHP version the web server actually executes.
FAQ
Why does PHP point at a line that looks fine?
Usually a semicolon or brace is missing before it. Check two or three lines above the message.
The error started right after a PHP upgrade – should I roll back?
As an emergency measure yes, but better to find and replace the removed syntax.
Why does php -l report no error but the web server does?
Console (CLI) and PHP-FPM or the Apache module can be different PHP versions. Check the web server's version via phpinfo() or php-fpm8.2 -v and lint with exactly that binary, for example php7.4 -l file.php.
How do I find syntax that does not fit the target PHP version?
Lint the files with the target version or use a tool such as PHPCompatibility for PHP_CodeSniffer, which names constructs not allowed in a version. For Composer packages also check the package's require entry for php.
How do I avoid the white screen in production?
Turn display_errors off and log_errors on, so visitors see no error details while you find them in the log. A lint step in the deployment pipeline with the production version catches parse errors before code reaches the server.