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
- Check the reported line and the one before it
- Run
php -l file.phpto lint - Verify the server PHP version supports the syntax
- Use an editor with PHP syntax highlighting
Detailed fix by platform
PHP
- 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 5Newer 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
- Line — Reported line and the one above
- Version — Server PHP version vs syntax used
- 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026