Is there a static code analyzer for PHP files? The binary itself can check for syntax errors, but I'm looking for something that does more, like unused variable assignments, arrays that are assigned into without being initialized first, and possibly code style warnings. Open-source programs would be preferred, but we might convince the company to pay for something if it's highly recommended.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
There is absolutely new tool for static code analysis called PHP Analyzer.
Among many types of static analysis it also provides basic auto-fixing functionality, see documentation.
UPDATE: PHP-Analyzer is now deprecated project but you still can access it on legacy branch
PHP Mess Detector is awesome and fast.
There is RIPS - A static source code analyser for vulnerabilities in PHP scripts. Sources of RIPS available at SourceForge.
From the RIPS site:
You may want to try compiling with Facebook's hiphop.
It does a static analysis on the entire project, and may be what you're looking for.
https://github.com/facebook/hiphop-php
For completeness -- also check phpCallGraph.
Run php in lint-mode from the command line to validate syntax without execution:
php -l FILENAME
Higher-level static analyzers include:
Lower-level analyzers include:
Runtime analyzers, which are more useful for some things due to PHPs dynamic nature, include:
The documentation libraries phpdoc and doxygen perform a kind of code analysis. Doxygen, for example, can be configured to render nice inheritance graphs with graphviz.
Another option is xhprof, which is similar to xdebug, but lighter, making it suitable for production servers. The tool includes a PHP-based interface.