A PHP parse error means PHP could not read the file at all, so none of it runs. The site usually shows a white page or a 500 error. The message names a file and a line number, which is where PHP noticed the problem. The actual mistake is often a line or two earlier.
Before you start
- Find the full error in the PHP error log. On cPanel, see find PHP errors in cPanel.
- Keep a copy of the file before you edit it.
Read the error message
PHP Parse error: syntax error, unexpected token "}", expecting ";" in /home/user/public_html/inc/functions.php on line 42Go to line 42, then look at the line above it. Here, a statement on line 41 is missing its semicolon.
Lint the file from the command line
Over SSH, check a file without running it:
php -l inc/functions.phpTo check a whole project:
find . -name "*.php" -exec php -l {} \; | grep -v "No syntax errors"Common variants and causes
| Message | Usual cause |
|---|---|
| unexpected end of file | A missing closing }, or an unclosed string or comment |
| unexpected token "}" / ")" | A missing ; or an extra bracket on the line before |
| unexpected identifier / T_STRING | Unescaped quotes inside a string, or a missing . between strings |
| unexpected variable | A missing operator or semicolon before a $variable |
| unexpected token "?" or "=>" / "fn" | Newer syntax on an older PHP version |
When the code is fine but PHP is too old
Plugins and themes written for PHP 8 use features like ?->, match, named arguments and typed properties. On PHP 7.x these produce parse errors even though the code is correct. Check which version the site uses and update it:
- cPanel: Software → MultiPHP Manager or Select PHP Version. See change the PHP version in cPanel.
- VPS: check
php -vand which PHP-FPM socket the site uses.
Plan the change with the PHP version upgrade checklist.
Errors after editing in the browser
If the error appeared right after you edited a WordPress theme or plugin file, upload the original file over FTP or the File Manager, or rename the plugin folder to disable it. Common slips are a deleted ?>, curly quotes pasted from a word processor, and code pasted after a closing tag.
FAQ
Why does the error point to the last line of the file?
"Unexpected end of file" means PHP reached the end while still waiting for a closing bracket or quote. Use an editor with bracket matching to find the unclosed block.
Can a parse error be caused by a file upload?
Yes. A file that uploaded only partly, or in ASCII FTP mode, can be cut off. Upload it again in binary mode.
Why don't I see the error, only a white page?
Display of errors is off in production. The message is still written to the error log; read it there rather than turning on display_errors on a live site.
