"syntax error, unexpected token" in PHP — What It Means and How to Fix It

What the PHP error "syntax error, unexpected token" means and how to fix it.

Published October 31, 2026

The PHP parser met a symbol it did not expect, so the script cannot run at all. The real mistake is usually on or just before the reported line.

What it means and why it happens

Typical causes: a missing semicolon, unbalanced braces or parentheses, a missing quote, or using syntax from a newer PHP version than the server runs.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Parse error: syntax error, unexpected token "}" in script.php on line 18

Practical examples

Code that triggers it

<?php
$name = 'Ada'
echo $name;   // missing semicolon on the line above

The fix

<?php
$name = 'Ada';
echo $name;

Lint the file

php -l script.php
php -v   # check the PHP version

Common mistakes

  • Looking only at the reported line (the mistake may be earlier).
  • Using PHP 8 syntax on PHP 7.
  • Mismatched quotes in strings.

Key takeaways

  • Syntax error, unexpected token: The PHP parser met a symbol it did not expect, so the script cannot run at all.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

How do I check syntax without running?

php -l file.php.

How do I find which line caused Syntax error, unexpected token?

The error message and stack trace show the file and line; start there and work backwards.

More PHP articles