Is php code syntax possible with php-cli?

Is it possible to check the syntax of php code (without running), similarly

php-cli -l 

when starting php the "normal" way (as a module)?

+4
source share
4 answers

There are also some PECL extensions that parse PHP code for various reasons. First up is BCompiler , which can compile PHP into byte code. Since this step requires parsing the PHP code, I would expect errors if it is not lint. Parsekit allwos you have to compile PHP code for OP codes, which is basically what you want. However, the extension has not been released since the end of 2009, so it may be deprecated. Parse_Tree has been sadly not supported since 2007, but its goal is to parse the PHP file in AST. Maybe you can get something with this, after some polishing.

PHP_Parser is a PEAR package that does not rely on special PHP extensions and tries to parse PHP code from PHP. Its marked alpha and unsupported, but it may give you reason to experiment.

+2
source

You can try to run a tool, such as PHP Depend , which tries to parse the data of PHP files into an abstract syntax tree. Although this may not catch all the errors of the PHP parser, it will catch quite a lot already.

You get good software performance as an extra product if the code is valid. :)

+1
source

Is it possible to check php-code syntax (without launching), similar to php-cli -l when starting php the "usual" way (as a module)?

I think that every missed question is that there is no difference in the PHP syntax whether you run it as a module or just execute binary code from the shell: PHP syntax is the same in both cases. That way you can just use php -l filename.php, as this has the same result as using the above tools.

0
source

To get the same result as php-cli -l, use the function: php_check_syntax

-1
source

Source: https://habr.com/ru/post/1340089/


All Articles