ParseError
PHPFATALCommonSyntax

PHP syntax error — script cannot be parsed

Quick Answer

Run php -l file.php to catch syntax errors before deploying.

What this means

Thrown when the PHP engine encounters a syntax error while parsing a file. Fatal before any code runs; only catchable via set_exception_handler or register_shutdown_function.

Why it happens
  1. 1Missing semicolon or closing brace
  2. 2Typo in a keyword or operator

Fix

Lint before deploying

Lint before deploying
php -l src/MyClass.php
# Outputs: No syntax errors detected in src/MyClass.php

Why this works

php -l parses the file without executing it, reporting syntax errors immediately.

Code examples
Triggerphp
<?php
echo "hello" // missing semicolon
echo "world";
Catch in bootstrapphp
register_shutdown_function(function () {
    $e = error_get_last();
    if ($e && $e['type'] === E_PARSE) {
        http_response_code(500);
        echo "Server error";
    }
});

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PHP errors