Parse error PHP Origin: Application & API Last updated 13 Oct 2026

PHP Parse error: syntax error, unexpected …

PHP can’t parse the file because of a syntax mistake — the real error is often on the line before the one reported.

Exact message you may see Parse error: syntax errorsyntax error, unexpectedunexpected end of fileunexpected token
Seen on: PHP

Meaning

The parser reports where it *noticed* the problem. A missing ;, ) or } on line 10 is often reported on line 11. “unexpected end of file” means an unclosed brace or string somewhere above.

Common causes

  • Missing semicolon, bracket or quote
  • Using newer syntax on an older PHP version (e.g. match, ?->, typed properties)
  • Unescaped quote inside a string
  • Copy-paste of smart quotes (“ ”) into code

⚡ Quick fix

  1. Check the reported line and the one before it
  2. Run php -l file.php to lint
  3. Verify the server PHP version supports the syntax
  4. Use an editor with PHP syntax highlighting

Detailed fix by platform

PHP

  1. Lint locally and on the server:
    bash
    php -l app/Http/Controllers/UserController.php
    php -v

Code examples

Missing semicolon reported on the next line

php
$total = $price * $qty     // ← the real mistake (line 4)
echo $total;               // Parse error: syntax error, unexpected token "echo" on line 5

Newer syntax on an old PHP version

php
// PHP 8.0+ only — on PHP 7.4 this is a parse error
$label = match ($status) { 'paid' => 'Paid', default => 'Open' };
$city  = $user?->address?->city;

Check php -v on the server (and the version selected in cPanel → MultiPHP Manager).

How to diagnose

  1. Line — Reported line and the one above
  2. Version — Server PHP version vs syntax used
  3. Balance — Brackets/quotes balanced?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

500 — HTTP 500 Internal Server Error (HTTP)500ArgumentCountError — Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected (PHP)ArgumentCountErrorCall to member function on null — Fatal error: Uncaught Error: Call to a member function x() on null (PHP)Call to member functi…Call to undefined function (WordPress) — WordPress: Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() / add_action() / get_header() (WordPress)Call to undefined fun…Cannot redeclare — Fatal error: Cannot redeclare function foo() (previously declared in …) (PHP)Cannot redeclareCritical error — WordPress: There Has Been a Critical Error on This Website (WordPress)Critical errorGraphQL Syntax Error — GraphQL: Syntax Error: Expected Name, found <EOF> / Unexpected } (API)GraphQL Syntax ErrorIndentationError — IndentationError: unexpected indent / expected an indented block (Python)IndentationErrorParse err…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.