PHP Syntax checking pre-source control

后端 未结 6 1447
孤城傲影
孤城傲影 2021-02-05 01:30

Referring to Is there a static code analyzer [like Lint] for PHP files? -- I am looking at how to assess the content of PHP files before they are committed by developers.

6条回答
  •  野的像风
    2021-02-05 02:30

    I think this might be a bit hard for an analyser to give warnings about. The code you've given might work with the help register_globals, for example. Also, it might be defined in some other file that is including this file. For those reasons, PHP files should be analyzed with full context of other files for this to be really reliable, and PHP/server configuration should also be either available or defined to the analyzing mechanism.

    That said, are you sure phplint doesn't do what you want to?

    There is an online validator that you can use to test it. Given the input:

    the result was:

            echo $foo;
                      \_ HERE
    ==== 3: ERROR: variable `$foo' has not been assigned
    END parsing of test-qBlPWw
    ==== ?: notice: unused package `dummy.php'
    ==== ?: notice: unused module `standard'
    Overall test results: 1 errors, 0 warnings.
    

    whereas with isset() it didn't find any issues.

    EDIT: so for this other test case:

    On Linux Mint 8 the response is:

    $ src/phplint test.php 
    /home/vadmin/phplint/phplint-pure-c-1.0_20110223/test.php:3: ERROR: variable `$foo' has not been assigned
    /home/vadmin/phplint/phplint-pure-c-1.0_20110223/test.php:3: Warning: comparing (unknown) == (string): cannot check the comparison between unknown types
    Overall test results: 1 errors, 1 warnings.
    

    and with this:

    it is:

    $ src/phplint test.php 
    /home/vadmin/phplint/phplint-pure-c-1.0_20110223/test.php:6: ERROR: comparing (string) == (int)
    Overall test results: 1 errors, 0 warnings.
    

    so isn't it working like it should, and reporting the problem properly?

提交回复
热议问题