


Xdebug Document (5) Code Coverage Analysis, xdebug Document_PHP Tutorial
Xdebug Document (5) Code coverage analysis, xdebug document
Code coverage analysis can let you know which line (or section) of the script is being executed when requested.
Related settings
xdebug.coverage_enable
Type: boolean, Default value: 1, starts with
Xdebug >= 2.2
If set to 0, Xdebug will not set up built-in structures to allow code analysis. This can speed up xdebug faster, but code coverage analysis will not work.
Related functions
boolean xdebug_code_coverage_started()
Returns a Boolean value to see if code coverage analysis has started.
Example:
<?<span>php </span><span>var_dump</span><span>(xdebug_code_coverage_started()); xdebug_start_code_coverage(); </span><span>var_dump</span><span>(xdebug_code_coverage_started()); </span>?>
Returns:
bool(false)
bool(true)
array xdebug_get_code_coverage()
Returns a structure containing which line of the script (including referenced files) is being executed. The following shows an example of code coverage specifying a certain file:
Example:
<?<span>php xdebug_start_code_coverage(); </span><span>function</span> a(<span>$a</span><span>) { </span><span>echo</span> <span>$a</span> * 2.5<span>; } </span><span>function</span> b(<span>$count</span><span>) { </span><span>for</span> (<span>$i</span> = 0; <span>$i</span> < <span>$count</span>; <span>$i</span>++<span>) { a(</span><span>$i</span> + 0.17<span>); } } b(</span>6<span>); b(</span>10<span>); </span><span>var_dump</span><span>(xdebug_get_code_coverage()); </span>?>
Returns:
array
'/home/httpd/html/test/xdebug/docs/xdebug_get_code_coverage.php' =>
array
5 => int 1
6 => int 1
7 => int 1
9 => int 1
10 => int 1
11 => int 1
12 => int 1
13 => int 1
15 => int 1
16 => int 1
18 => int 1
void xdebug_start_code_coverage( [int options] )
Start code coverage analysis
This function starts collecting code coverage information. This information is formed by a two-dimensional array. The first-dimensional index is the execution file name and the second-dimensional index is the line number. The element value indicates whether the line was executed or it has unreachable lines.
Value returned for each row:
- 1: This line has already been executed
- -1: This line has not been executed
- -2: This line has no executable code
The -1 value will only be returned when XDEBUG_CC_UNUSED is turned on, and the -2 value will be returned only when XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE are turned on at the same time.
The function has two options with enumeration values:
XDEBUG_CC_UNUSED
Enable code detection and indicate which lines of code are executable. Without this item, the returned array only contains the actual executed line numbers.
XDEBUG_CC_DEAD_CODE
Start additional analysis to show which code can be executed.
If these options are enabled, code coverage analysis will be significantly slowed down.
The following examples show how to use the options:
Example:
<?<span>php xdebug_start_code_coverage( XDEBUG_CC_UNUSED </span>|<span> XDEBUG_CC_DEAD_CODE ); </span>?>
void xdebug_stop_code_coverage( [int cleanup=true] )
Stop code coverage analysis
This function stops collecting information and the information will be cleared in memory. If you pass the "false" parameter, the code coverage information will not be cleared and you can use xdebug_start_code_coverage() again to resume information collection.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool