Home > Article > Backend Development > How to use php's lint to check for syntax errors
The syntax check in How to use phps lint to check for syntax errors is very important. This article will introduce to you how to use lint in How to use phps lint to check for syntax errors to perform syntax check before running the program. Let’s take a look at the specific content.
Checking from the command line (lint)
Checking from the command line means you can check the entire How to use phps lint to check for syntax errors file
You don't have to write the function in your code to check.
Let’s look at a program first
test1.How to use phps lint to check for syntax errors <?How to use phps lint to check for syntax errors $i = 1; if($i == 1){ echo "学生"; ?>
Write the command as follows.
How to use phps lint to check for syntax errors -l test1.How to use phps lint to check for syntax errors
Result
PHP Parse error: syntax error, unexpected end of file in test1.How to use phps lint to check for syntax errors on line 5 Errors parsing test1.How to use phps lint to check for syntax errors
The above error occurred when running the command. The error is also displayed as line 5 (the fifth line) because the curly braces are not closed.
We check the syntax and correct it and check again after knowing the error
<?How to use phps lint to check for syntax errors $i = 1; if($i == 1){ echo "学生"; } ?>
Write the command as follows.
How to use phps lint to check for syntax errors -l test2.How to use phps lint to check for syntax errors
Result
No syntax errors detected in test2.How to use phps lint to check for syntax errors
If the above result is displayed, there is no syntax error.
Check the code directly (runkit_lint)
Next, you can use runkit_lint to check in the PHP code
This function must have a PHP library (Picle) named PECL, otherwise you cannot use this function, and you need to enable thread safety
If you are interested, you can go to the official website to query and prepare the environment to try, I won’t go into details here.
The above is the detailed content of How to use php's lint to check for syntax errors. For more information, please follow other related articles on the PHP Chinese website!