PHP has become one of the most popular programming languages, but many PHP programmers fret that they can't find the right tools to help them analyze and parse PHP code. Today's small series for you to introduce a few very good tools to help programmers improve their work efficiency, take a look at it!
PHP Parser
Php-parser is a PHP parser written in PHP (which supports PHP 5.4 and earlier), and this particular parser is ideal for static code analysis. The purpose of this tool is to simplify static code analysis and operations, which enables programmers to programmatically process code for any application.
Phpsandbox
Phpsandbox will run PHP as a way of standalone processes. It provides programmers with the protection of a perimeter script, such as errors, crashes, slow scripts, or scripts that are not suitable for running in code, and can be run as stand-alone processes.
PHP Mess Detector
PHPMD This tool can detect some potential problems in the PHP source code. For example:
- Bugs that may exist
- Code that is not up to the best standard
- Too complex a grammar
- Parameters, methods, properties that have never been used
Phpcpd
PHPCPD is a tool that looks for similar patterns in code, using it to identify where code is copied or pasted in the code base. This is a useful tool in the general build process that helps programmers analyze code to avoid calling functions repeatedly in code libraries.
Phpcheckstyle
Phpcheckstyle is a tool that helps PHP programmers check code and report errors, running in PHP 5.0 and a higher version. Invoking Phpcheckstyle in the form of an SVN hook script can force code to conform to pre-set coding standards (such as pear coding standards), helping to improve the overall quality of the code in a multiplayer project.
Ubench
Ubench is a development library for evaluating the execution time of PHP code and the efficiency of memory usage. Use the following methods:
require_once 'src/Ubench.<span id="1_nwp" style="width: auto; height: auto; float: none;"><a id="1_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=11&is_app=0&jk=f35ff87300cda873&k=php&k0=php&kdi0=0&luki=8&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=73a8cd0073f85ff3&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="1" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">php</span></a></span>';
$bench = new Ubench;
$bench->start();
// Execute some code
$bench->end();
// Get elapsed time and <span id="2_nwp" style="width: auto; height: auto; float: none;"><a id="2_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=11&is_app=0&jk=f35ff87300cda873&k=memory&k0=memory&kdi0=0&luki=4&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=73a8cd0073f85ff3&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="2" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">memory</span></a></span>
echo $bench->getTime(); // 156ms or 1.123s
echo $bench->getTime(true); // elapsed microtime in float
echo $bench->getTime(false, '%d%s'); // 156ms or 1s
echo $bench->getMemoryPeak(); // 152B or 90.00Kb or 15.23Mb
echo $bench->getMemoryPeak(true); // memory <span id="3_nwp" style="width: auto; height: auto; float: none;"><a id="3_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=11&is_app=0&jk=f35ff87300cda873&k=peak&k0=peak&kdi0=0&luki=3&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=73a8cd0073f85ff3&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="3" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">peak</span></a></span> in bytes
echo $bench->getMemoryPeak(false, '%.3f%s'); // 152B or 90.152Kb or 15.234Mb
// Returns the memory usage at the end <span id="4_nwp" style="width: auto; height: auto; float: none;"><a id="4_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=11&is_app=0&jk=f35ff87300cda873&k=mark&k0=mark&kdi0=0&luki=2&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=73a8cd0073f85ff3&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F6257%2Ehtml&urlid=0" target="_blank" mpid="4" style="text-decoration: none;"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">mark</span></a></span>
echo $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb
PHP Analyzer
The PHP Analyzer performs the same flow analysis as the compiler, ensuring that the code performs tests on every line of the potential execution path. This special tool helps developers improve their code quality to ensure productivity.