Verification: a143cc29221c9be0

Php check syntax all files

Syntax checking a single PHP file from the command line

The syntax for checking is like this, where the -l flag is a lower case L:

php -l filename

If the syntax in the file is correct you will see this:

No syntax errors detected in test.php

If there are errors then theses will be listed as in the following example output:

Parse error: syntax error, unexpected T_STRING in test.php on line 5
Errors parsing test.php

Note that the syntax checking only checks for syntax errors – it does not report the usage of variables which have not yet been defined, functions or class which have not be declared etc.

So something like this will pass:

but these will not:

 1;
something {
}

Syntax check all PHP files in the current directory

This was posted by @chrisvoo (http://twitter.com/chrisvoo) to syntax check all the PHP files (or at least all files with a .php extension) in the current directory from a BASH command line:

for i in *.php; do php -l $i; done

Syntax check all PHP files in the current directory and all subdirectories

I retweeted the above and was replied to by @gurubobnz on Twitter (http://twitter.com/gurubobnz) with how to syntax check all .php files recursively down the directory tree from current directory:

find . -name *.php -exec php -l "{}" ;

Syntax checking a single PHP file from the command line

The syntax for checking is like this, where the -l flag is a lower case L:

php -l filename

If the syntax in the file is correct you will see this:

No syntax errors detected in test.php

If there are errors then theses will be listed as in the following example output:

Parse error: syntax error, unexpected T_STRING in test.php on line 5
Errors parsing test.php

Note that the syntax checking only checks for syntax errors – it does not report the usage of variables which have not yet been defined, functions or class which have not be declared etc.

So something like this will pass:

but these will not:

 1;
something {
}

Syntax check all PHP files in the current directory

This was posted by @chrisvoo (http://twitter.com/chrisvoo) to syntax check all the PHP files (or at least all files with a .php extension) in the current directory from a BASH command line:

for i in *.php; do php -l $i; done

Syntax check all PHP files in the current directory and all subdirectories

I retweeted the above and was replied to by @gurubobnz on Twitter (http://twitter.com/gurubobnz) with how to syntax check all .php files recursively down the directory tree from current directory:

find . -name *.php -exec php -l "{}" ;

User guide

To check syntax code:

  • First, Drag and drop your PHP file or copy / paste your PHP text directly into the editor above.
  • Finally, you must click on "Check PHP syntax" button to display if there is an syntax error in your code.

PHP code checker tool

PHP is a server-side scripting language, but can also be used as a general-purpose programming language.

PHP error checker tool allows to find syntax errors (lint). You can test your PHP code online directly in your browser.

If a syntax error is detected, then the line in error is highlighted, and it jumps to it to save time (no need to search the line).

It can be useful to make online test to save time (deployment ...).

Note: If you want to run php code you can use our PHP Online tool.


API

An API is available to test the syntax of your php scripts.

POST https://api.extendsclass.com/php-checker/:PHPVersion

Check the PHP syntax. PHP versions: 5.6.40, 7.4.8, 8.0.0.

Request

JavaScript example:

const request = new XMLHttpRequest();
request.open("POST", "https://api.extendsclass.com/php-checker/8.0.0", true);
request.onreadystatechange = () => {
};
request.send('');

Response

Success: 200

{
   "code":0,
   "stdout":"No syntax errors detected"
}

Error: 400

{
    "code": 4294967295,
    "stdout": "\nParse error: syntax error, unexpected 'dir' (T_STRING) in file on line 3\nErrors parsing file\n"
}

Error: 500

PHP version is not available