Static Analysis with HipHop for PHP

Sebastian Bergmann » 27 January 2012 » in PHP » 3 Comments

In July 2010 I already blogged about the fact that HipHop for PHP, the source code transformer that turns PHP code into C++ code that can then be compiled with g++, can also be used for static code analysis to find problems in PHP source code.

Today I started to work on a convenience wrapper for HipHop's static analyzer:

➜  ~  hphpa /usr/local/src/code-coverage/PHP
hphpa 1.0.0 by Sebastian Bergmann.

/usr/local/src/code-coverage/PHP/CodeCoverage/Filter.php
  206   TooManyArgument: $this->addFileToWhitelist($file, FALSE)

Of course the tool can also generate an XML logfile in a format that is suitable for continuous integration:

➜  ~  hphpa --checkstyle hphpa.xml --quiet /usr/local/src/code-coverage/PHP
hphpa 1.0.0 by Sebastian Bergmann.

➜  ~  cat hphpa.xml
<checkstyle>
 <file name="/usr/local/src/code-coverage/PHP/CodeCoverage/Filter.php">
  <error line="206"
         message="$this->addFileToWhitelist($file, FALSE)"
         source="TooManyArgument"/>
 </file>
</checkstyle>
Defined tags for this entry: , ,

Trackback specific URI for this entry

3 Comments to "Static Analysis with HipHop for PHP"

Display comments as (Linear | Threaded)
  1. David
    28/01/2012 at 11:19 Permalink
    That looks awesome Sebastian, thanks for all your work! Can't wait to give it a whirl

    Reply

  2. Stas
    30/01/2012 at 10:17 Permalink
    Does it reuse phpcs rules? That would be great - combining C speed with phpcs rule system.

    Reply

  3. Sebastian Bergmann
    30/01/2012 at 10:21 Permalink
    No, it just emits warnings and errors it finds during the transformation from PHP to C++. Undeclared variables and methods, too many/few arguments in function/method calls, etc.

    Interesting idea, though: compile PHP_CodeSniffer with HipHop to have a faster PHP_CodeSniffer. Will look into that!

    Reply

0 Trackbacks to "Static Analysis with HipHop for PHP"

  1. No Trackbacks

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.