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