Seven tools for analyzing and parsing PHP code

Source: Internet
Author: User
Tags php source code

Seven tools for analyzing and parsing PHP code

PHP has become one of the most popular programming languages nowadays, but many PHP programmers cannot find the right tools to help them analyze and parse PHP code. Today, I will introduce several very good tools to help programmers improve their work efficiency. Let's take a look!

PHP Parser

PHP-Parser is a PHP Parser compiled in PHP that supports PHP 5.4 and earlier versions. This special Parser is very suitable for static code analysis. The tool aims to simplify static Code Analysis and Operations, and enables programmers to process code of any application programmatically.

PHPSandbox

PHPSandbox uses PHP as a standalone process. It protects programmers from peripheral scripts, such as errors, crashes, slow running scripts, or scripts that are not suitable for running in code.

PHP Mess Detector

PHPMD is a tool that can detect some potential problems in PHP source code. For example:

  • Possible bugs
  • Code that does not meet the best standards
  • Too complex syntax
  • Parameters, methods, and attributes that have never been used

PHPCPD

PHPCPD is a tool for finding similar patterns in code. It is used to identify where the code is copied or pasted in the code base. This is a very useful tool in the conventional build process. It helps programmers analyze the code to avoid repeated function calls in the code base.

PHPCheckstyle

PHPCheckstyle is a tool that helps PHP programmers check code and report errors. It runs in PHP 5.0 and later versions. Using the SVN hook script to call PHPCheckstyle can force the code to comply with pre-defined encoding standards, such as PEAR encoding standards, to improve the overall quality of the Code in multi-person projects.

Ubench

Ubench is a development library used to evaluate PHP code execution time and memory usage efficiency. The usage is as follows:

 
 
  1. 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>'; 
  2.  
  3. $bench = new Ubench; 
  4.  
  5. $bench->start(); 
  6.  
  7. // Execute some code 
  8.  
  9. $bench->end(); 
  10.  
  11. // 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> 
  12.  
  13. echo $bench->getTime(); // 156ms or 1.123s 
  14.  
  15. echo $bench->getTime(true); // elapsed microtime in float 
  16.  
  17. echo $bench->getTime(false, '%d%s'); // 156ms or 1s 
  18.  
  19. echo $bench->getMemoryPeak(); // 152B or 90.00Kb or 15.23Mb 
  20.  
  21. 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 
  22.  
  23. echo $bench->getMemoryPeak(false, '%.3f%s'); // 152B or 90.152Kb or 15.234Mb 
  24.  
  25. // 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> 
  26.  
  27. echo $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb

PHP Analyzer

PHP Analyzer executes the same flow analysis as the compiler, ensuring that the code is tested on every line of each potential execution path. This special tool helps developers improve their code quality and ensure work efficiency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.