Parse error 🐘 PHP

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.

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

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 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.