PHP

Parse error: syntax error (PHP)

PHP couldn't even compile the file — there's a syntax mistake, usually just before the line it names.

What it looks like

PHP Parse error:  syntax error, unexpected token "}" in /var/www/app/index.php on line 27

What does "Parse error: syntax error (PHP)" mean?

Raised before any code runs: PHP could not compile the file, so the whole page fails, often as a blank page or a 500 error. The reported line is where PHP noticed the problem; the mistake is usually on the line above it.

What causes "Parse error: syntax error (PHP)"?

  • A missing semicolon, brace, or parenthesis.
  • An unclosed string or comment.
  • Mismatched quotes/brackets.

How do I confirm the cause?

  1. Run php -l path/to/file.php to get the error without loading the page.
  2. Check the line before the one reported for a missing semicolon, bracket or closing quote.
  3. An “unexpected end of file” means a brace or bracket opened somewhere earlier was never closed.

How do I fix "Parse error: syntax error (PHP)"?

  • Open the file at the reported line and check the line above it.
  • Match every brace, bracket, parenthesis and quote.
  • Use a linter (php -l file.php).

How do I stop it happening again?

  • Use an editor that highlights PHP syntax errors, and run php -l in a pre-commit hook or CI.
  • Upload files over a method that cannot truncate them (a deploy script or git, not a half-finished FTP copy).
Got a different error? Paste it into the Explain This Error tool → Identifies the family and the fix — runs locally, nothing uploaded.

Related errors