How to Check PHP Syntax Errors (php -l, VS Code, Online)
A php syntax checker answers one question: will the engine parse this file? The authoritative command is php -l. FlashKit’s PHP code syntax checker is a quicker, weaker first pass: JavaScript heuristics in this tab, no PHP binary, no upload. Treat it like a spell-check, then lint with the runtime you actually ship. Markup and SQL are different jobs — HTML5 validation and the SQL formatter do not parse PHP.
php -l and what it does not catch
Ran php -v on 10 Nov 2026:
PHP 8.3.6 (cli) (built: Oct 19 2026 15:16:58) (NTS)
Zend Engine v4.3.6
php -l file.php tokenizes and parses. On success it prints No syntax errors detected in file.php. On failure it prints a PHP Parse error: and Errors parsing file.php, exit status non-zero. It does not execute the file. It does not load autoloaders. It will not tell you that foo() is undefined, that a type hint was violated, or that a query string is wrong. For those, use PHPStan or Psalm in CI, on the same major version as production.
Quick in-tab pass (not php -l)
Line-based JS: missing semicolons on echo/return/assignments, brace/paren counts, missing <?php. Local, no PHP engine.
Open the PHP syntax checkerDecode 8 common parse errors with snippets
Each snippet was saved and run through php -l on PHP 8.3.6. The quoted messages are the CLI’s words, not a paraphrase.
1. Missing semicolon before the next statement
<?php
$name = "World"
echo "Hello $name";
php -l: PHP Parse error: syntax error, unexpected token "echo" in /tmp/php-lint-samples/01-missing-semicolon.php on line 3. PHP notices the next token, not the missing ; on line 2. Add the semicolon on the assignment. FlashKit’s heuristic will flag line 2 as “Possible missing semicolon (; )” because it sees = and no terminator — that is the one case where the JS pass is more specific than php -l.
2. Unclosed brace
<?php
function greet($name) {
return "Hello $name";
PHP Parse error: Unclosed '{' on line 2 in /tmp/php-lint-samples/02-unclosed-brace.php on line 4. Close the function. The checker counts { vs } across the paste and reports Unclosed brace "}". Missing 1. on the last line.
3. Unclosed string
<?php
$msg = "Hello World;
echo $msg;
PHP Parse error: syntax error, unexpected end of file in /tmp/php-lint-samples/03-unclosed-string.php on line 4. The quote started on line 2 never ended, so the rest of the file is still a string. FlashKit does not parse quotes; php -l is the check that catches this.
4. Extra closing brace
<?php
function greet($name) {
return "Hello $name";
}
}
PHP Parse error: Unmatched '}' in /tmp/php-lint-samples/04-extra-brace.php on line 5. Delete the stray }. The JS pass reports Extra closing brace "}" detected.
5. Unclosed parenthesis in a call
<?php
echo strtoupper("hello";
PHP Parse error: syntax error, unexpected token ";", expecting ")" in /tmp/php-lint-samples/05-unclosed-paren.php on line 2. Close the strtoupper( call. FlashKit’s paren counter reports Unclosed parenthesis ")". Missing 1.
6. if / else without braces, missing semicolon
<?php
if (true) echo "ok" else echo "no";
PHP Parse error: syntax error, unexpected token "else", expecting "," or ";" in /tmp/php-lint-samples/06-unexpected-echo.php on line 2. The alternative syntax needs a semicolon after echo "ok", or use braces. FlashKit skips lines that start with if, so this file can look “clean” in the online box and still fail php -l. That is the honesty line: the online php syntax checker is not the parser.
7. Missing comma in an array
<?php
$a = [
"one"
"two",
];
PHP Parse error: syntax error, unexpected double-quoted string "two", expecting "]" in /tmp/php-lint-samples/07-array-missing-comma.php on line 4. Put a comma after "one". The JS heuristic looks for = / echo / return / print and will not necessarily flag a missing array comma.
8. Two statements, first missing semicolon
<?php
$a = 1
$b = 2;
PHP Parse error: syntax error, unexpected variable "$b" in /tmp/php-lint-samples/08-unexpected-variable.php on line 3. Same class as snippet 1: the error is reported on the following token. Add ; after 1.
VS Code / PhpStorm linting
VS Code with a PHP file: the built-in language features plus an extension such as Intelephense underline parse errors while you type. Point php.validate.executablePath (or Intelephense’s environment) at the same binary you run in CI — 8.3 here. PhpStorm: Settings → PHP language level matching production, then the Inspections for syntax. Neither replaces php -l on the CI image; they shrink the time to the first red squiggle. Format-on-save is a style tool, not a parser.
Git pre-commit hook
Scratch repo at /tmp/php-hook-demo on 10 Nov 2026, hook .git/hooks/pre-commit:
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php