Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Syntax checking pre-source control
    primarykey
    data
    text
    <p>Referring to <a href="https://stackoverflow.com/questions/378959/is-there-a-static-code-analyzer-like-lint-for-php-files">Is there a static code analyzer [like Lint] for PHP files?</a> -- <em>I am looking at how to assess the content of PHP files before they are committed by developers.</em> Whichever solution(s) are appropriate will be triggered via SVN hooks similar to the answer: <a href="https://stackoverflow.com/questions/1208154/is-it-possible-to-check-php-file-syntax-from-php">Is it possible to check PHP file syntax from PHP?</a></p> <p>I came across this <a href="http://pookey.co.uk/wordpress/archives/34-automatically-syntax-checking-of-php-files-when-checking-to-svn" rel="nofollow noreferrer">Automatic Syntax checking of PHP files when checking into SVN</a> which is the angle I'm going for, however ... <code>php -l</code> isn't quite sufficient. </p> <p>For example, given the code:</p> <pre><code>if ($foo == 'bar') { echo $foo; } </code></pre> <p>This results in:</p> <blockquote> <p>2012/01/15 02:51:14 [error] 694#0: *164 FastCGI sent in stderr: "PHP Notice: Undefined variable: foo</p> </blockquote> <p>Compared to:</p> <pre><code>if (isset($foo)) { echo $foo; } </code></pre> <p>Some of this comes down to educating coders on best practices. Unfortunately, some don't learn as quickly as others, and the only way to ensure that compliance to coding standards is met, is to reduce what is going into SVN that has been untested or isn't compliant. </p> <p>From the first link in this question, I have tried:</p> <ul> <li>php -l <ul> <li>doesn't notify about the problem with <code>$foo</code></li> </ul></li> <li><a href="http://www.icosaedro.it/phplint/" rel="nofollow noreferrer">phplint-pure-c-1.0_20110223 - PHPLint</a> <ul> <li>doesn't notify about the problem with <code>$foo</code></li> </ul></li> </ul> <blockquote> <pre><code> if ($foo == 'bar') { \_ HERE </code></pre> <p>==== /mnt/hgfs/workspace/scratch-pad/phpinfo.php:44: Warning: comparing (unknown) == (string): cannot check the comparison between unknown types</p> </blockquote> <ul> <li><a href="http://pear.php.net/package/PHP_CodeSniffer" rel="nofollow noreferrer">phpcs - PHP Code Sniffer</a> <ul> <li>doesn't notify about the problem with <code>$foo</code> despite <a href="https://stackoverflow.com/questions/2097037/php-sanity-check">PHP Sanity Check</a> indicating it was the right answer</li> </ul></li> <li><a href="http://www.simpletest.org/" rel="nofollow noreferrer">SimpleTest</a> <ul> <li>Is very nice, but requires the developers who are writing the bad code to write <em>good</em> unit tests...</li> </ul></li> </ul> <p>All are interesting in their own way, but none are catching these problems that really are only being found at runtime. </p> <p>Appreciate input / thoughts on this topic.</p> <p><strong>EDIT</strong></p> <p>There was one poster who suggested that PHPLint was the right way to go. I thought, OK! Let's try it again given that there is a new version: <a href="http://www.icosaedro.it/phplint/download.html" rel="nofollow noreferrer">phplint-pure-c-1.1_20120202</a>:</p> <pre><code> &lt;?php if ($foo == 'bar') { echo $foo; } ?&gt; </code></pre> <p>Simple test .................... and, <strong>it works</strong> and reports 1 error, 1 warning. However, if the following is added <em>BEFORE</em> the <code>if</code> statement: </p> <pre><code> &lt;?php if (isset($foo) &amp;&amp; $foo == 'bar') { echo 'man'; } if ($foo == 'bar') { echo $foo; } ?&gt; </code></pre> <p><strong>it does not work</strong>, and reports 0 errors, 2 warnings.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload