Skip to content
PHP and Laravel3 min read

PHP Parse error: syntax error, unexpected: causes and fixes

PHP Parse error: syntax error, unexpected token

Short answer

A Parse error means PHP couldn't understand how the code is written, so the file never ran at all. The cause is usually a missing semicolon, an unclosed bracket or quote, or code using newer syntax than the server's PHP version. Open the file at the reported line and check the line before it.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. What the error means
  2. Common causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

This error happens before a single line of the file runs, because PHP reads and parses the whole file first. One typo in a file like functions.php is enough to take down the entire site with a 500 error, a blank page or WordPress’s critical error message.

What the error means

A PHP 8 example:

PHP Parse error:  syntax error, unexpected token "}" in /home/user/public_html/index.php on line 14

PHP reached a } on line 14 before the previous statement was finished, most often because a ; is missing. The real mistake is usually on the line before the reported number.

Common causes

Message Usual cause
unexpected token "}" or unexpected identifier Missing semicolon on the previous line
unexpected end of file or Unclosed '{' on line 5 A { that was never closed
unexpected token "<" An extra <?php tag inside PHP code after pasting a snippet
unexpected identifier next to plain text Curly quotes “ ” copied from Word or a blog
Error on a line using modern syntax The code needs a newer PHP version than the one enabled

A version example: PHP 8.4 lets you write new Invoice()->send() without parentheses around new, but the same line is a Parse error on PHP 8.3 and earlier.

How to fix it

  1. Read the file and line from the message. If the page is blank, find it in cPanel under Metrics › Errors or in the error_log file.
  2. Open the file in Files › File Manager › Edit, go to the reported line and check the line before it: semicolons, (), {} and [] pairs, and quotes.
  3. If you just pasted code into WordPress, remove it entirely to bring the site back, then add it again carefully. If you don’t know which file, rename the theme folder in wp-content/themes so WordPress falls back to an installed default theme.
  4. Lint with php -l if you have SSH. It checks the file without running it:
php -l app/Http/Controllers/OrderController.php
# No syntax errors detected in app/Http/Controllers/OrderController.php

To check every project file except vendor:

find . -name "*.php" -not -path "./vendor/*" -print0 | xargs -0 -n1 php -l | grep -v "No syntax errors"
  1. Check the PHP version: compare the version required in the library’s composer.json or the plugin page with the one in Software › Select PHP Version. See choosing a PHP version.
  2. Go back to a working copy if you use Git:
git diff path/to/file.php
git checkout -- path/to/file.php

Prevention

  • Write code in an editor with PHP linting, such as VS Code with a PHP extension, so mistakes are flagged before you save.
  • Don’t edit live files directly; change them locally or on staging, then deploy.
  • Add php -l to your deploy steps or a pre-commit Git hook.
  • Put custom WordPress code in a child theme or a snippets plugin, not the parent theme.

On ArabyHost

You can edit any file in the cPanel File Manager editor, one click from the Araby Panel, without SSH. Available versions are PHP 8.1, 8.2 and 8.3 per site, so avoid PHP 8.4-only syntax. The Araby AI assistant reads the error log and points to the faulty line. On developer plans you get SSH to run php -l, and JetBackup keeps a daily backup so you can restore the file as it was.

FAQ

Why does the error point to a line that looks fine?

PHP reports the error when it reaches something it didn't expect, which is usually after the real mistake. A missing semicolon on line 13 is reported on line 14, and an unclosed brace shows up at the end of the file.

How do I recover if a functions.php edit took down WordPress?

Open the file in cPanel File Manager and remove or fix the code you added. If you can't find it, rename the theme folder so WordPress falls back to a default theme, or restore the file from a backup.

Can the PHP version cause a Parse error?

Yes. Code written for a newer version, such as PHP 8.4 features, throws a Parse error on PHP 8.3. Check the version a library or plugin requires before installing it.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.