PHP Validator
Find the parse error before you upload the file.
About the PHP Validator
What is a PHP validator?
A PHP validator checks your code for the structural mistakes that stop a file from running at all. A missing semicolon, a brace that never closes, a quote left hanging, a heredoc whose closing marker got indented wrong. Any one of these gives you the white screen and a Parse error in the log instead of a page. This tool reads your code the way PHP's own tokenizer does and points at the exact line and column where the structure breaks, with the offending line printed underneath and a caret under the spot.
What separates it from the other checkers is where it runs. Every other PHP validator we found uploads your file to a server and lints it there. This one runs entirely in your browser, so nothing you paste leaves your machine, results come back as fast as you type, and the whole thing keeps working with the network off. It also understands current PHP, including enums, match, attributes, readonly properties, nullsafe calls and first-class callable syntax, so modern code is never mistaken for broken code.
It checks in two stages. A structural pass runs on every keystroke and is the part that gives you useful sentences instead of parser jargon, telling you which line lost its semicolon or that fnction should probably be function, and listing several problems at once rather than stopping at the first. When that pass finds nothing, the file goes through a full PHP parser before the badge turns green, so a clean result is a real one.
How to Use This Tool
- Add your PHP. Paste it into the left editor, click Open file, or try the Valid and Broken samples.
- Read the badge. Green means no structural error was found. Otherwise it counts the problems.
- Click an error. The editor jumps straight to the line and column where the structure breaks.
- Fix and repeat. Validation re-runs as you type, so each fix updates the list right away.
Example
Here is the most common PHP mistake there is. A statement is missing its semicolon, and this input will be converted to a report naming the exact line:
<?php
function calculateTotal(array $items): float
{
$total = 0
foreach ($items as $item) {
$total += $item['price'];
}
return $total;
}
Line 5:15
Missing semicolon at the end of
line 5. The statement "foreach"
on the next line cannot follow
it directly.
$total = 0
^
PHP itself would have blamed line 6, because that is where the parser finally gives up. Pointing at line 5 is the difference between a five second fix and ten minutes of staring at a foreach that was fine all along.
Common Use Cases
- Chasing a white screen: A parse error takes the whole page down with no output. Paste the file here and get the line instead of digging through the error log.
- Checking before you deploy: Catch the broken file on your machine rather than after it is live on the server.
- Finding the unclosed brace: Get pointed at the
{that was never closed, not at the last line of the file where PHP notices. - Vetting code you did not write: Sanity-check a snippet from a tutorial, a Stack Overflow answer, or an AI before you run it.
- Working on a shared host: No SSH and no
php -lavailable? This does the structural half of the same job in a browser tab.
Valid but hard to read? The PHP Formatter re-indents it and the PHP Minifier strips it down for shipping. Or browse all our free developer tools.
Frequently Asked Questions
What kinds of errors does it catch?
The structural ones that stop a file from parsing: unclosed or mismatched braces, brackets and parentheses, a stray closing bracket, a missing semicolon between statements, an unterminated single or double quoted string, a block comment with no */, and a heredoc or nowdoc whose closing marker never appears. These are the mistakes that produce Parse error: syntax error and take the whole file down.
If it says valid, will my code definitely parse?
Yes. A green badge means a real PHP parser read the whole file and accepted it, not just that the brackets balanced. The check runs in two stages: a fast structural pass answers as you type and reports several problems at once with plain-English messages, and when that pass comes back clean the file goes through a full PHP parser before the badge turns green. We measured it by taking real files and breaking them 738 different ways. PHP itself rejected 609 of those, and the tool caught all 609, with no valid file ever flagged.
Parsing is not the same as working, though. It cannot tell you a function does not exist, a class will not autoload, or your logic is wrong, and a few problems PHP only reports when it compiles or runs the file, such as an empty array element in [1, , 2], are not syntax errors at all. Read a green badge as "this file will parse," not "this code is correct."
Will it wrongly flag modern PHP?
No. We ran it across 1,198 real PHP files, including the Stripe and PHPMailer libraries, and checked every answer against PHP 8's own parser. It did not flag a single valid file. It handles enums, match, attributes such as #[Route], readonly promoted properties, union and intersection types, nullsafe operators, first-class callables, named arguments, numeric separators, and the flexible heredoc syntax from PHP 7.3.
Does my code get uploaded to a server?
No, and this is the main thing that sets it apart. The other PHP checkers online send your file to their server to lint it. Here the whole check runs in your browser with a locally served engine, no CDN and no round trip, so your code never leaves the machine and the tool keeps working offline once the page has loaded. That matters when the file has database credentials or API keys in it.
Which PHP version does it target?
Modern PHP 8, and it accepts everything back through PHP 5's syntax too. Because it checks structure rather than any one release's function library, code written for an older version validates the same way. It will not tell you that a PHP 8 feature is unavailable on your PHP 7 host, which is a separate question from whether the file parses.
Why does it report one bracket error at a time?
An unclosed brace makes everything after it read as part of the same block, which hides every real error that follows. So when the brackets do not balance, that gets reported on its own, because fixing it is what lets the rest of the file be checked properly. Unterminated strings and comments are listed together, since those can be found independently.
Does it work on a file with HTML in it?
Yes. Anything outside <?php and ?> is treated as literal output and skipped, exactly as PHP does, so template files with HTML wrapped around the code validate correctly. Short echo tags, the alternative if: endif; syntax, and files that open and close PHP several times all work. If a file has no <?php tag at all, you get a note saying so, since that usually means the opening tag was left off by accident.