代码覆盖分析能在请求时让你知道脚本哪一行(或哪一段)在执行。
相关设置
xdebug.coverage_enable
类型: boolean, 默认值: 1, 始于
Xdebug >= 2.2
如果设为0, Xdebug不会设置内置结构来允许代码分析,这能加速xdebug快些,不过代码覆盖分析将不会工作。
相关函数
boolean xdebug_code_coverage_started()
返回布尔值查看代码覆盖分析是否已经开始。
Example:
<span style="color: #000000;">php </span><span style="color: #008080;">var_dump</span><span style="color: #000000;">(xdebug_code_coverage_started()); xdebug_start_code_coverage(); </span><span style="color: #008080;">var_dump</span><span style="color: #000000;">(xdebug_code_coverage_started()); </span>?>
Returns:
bool(false)
bool(true)
array xdebug_get_code_coverage()
返回一结构包含脚本哪一行(包括引用文件)在执行。以下展示代码覆盖指定某一文件示例:
Example:
<span style="color: #000000;">php xdebug_start_code_coverage(); </span><span style="color: #0000ff;">function</span> a(<span style="color: #800080;">$a</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$a</span> * 2.5<span style="color: #000000;">; } </span><span style="color: #0000ff;">function</span> b(<span style="color: #800080;">$count</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> $count; <span style="color: #800080;">$i</span>++<span style="color: #000000;">) { a(</span><span style="color: #800080;">$i</span> + 0.17<span style="color: #000000;">); } } b(</span>6<span style="color: #000000;">); b(</span>10<span style="color: #000000;">); </span><span style="color: #008080;">var_dump</span><span style="color: #000000;">(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] )
开始代码覆盖分析
该函数开始收集代码覆盖信息。该信息由二维数组形成,一维索引为执行文件名二级索引为行号。元素值表示该行是否被执行或它拥有未能到达的行。
每行返回的值:
- 1: 该行已执行过
- -1: 该行未被执行
- -2: 该行没有可执行的代码
-1 值只有在 XDEBUG_CC_UNUSED 开启后才会返回,而 -2 值只有XDEBUG_CC_UNUSED 和 XDEBUG_CC_DEAD_CODE 同时开启才会返回。
函数有两个以枚举值的选项:
XDEBUG_CC_UNUSED
开启检测代码并说明哪行为可执行代码。无此项则返回的数组只包含实际执行过的行号。
XDEBUG_CC_DEAD_CODE
开始额外的分析说明哪些代码能被执行。
如果开启这些选项执行大幅减慢代码覆盖分析速度。
以下示例展示如何使用选项:
Example:
<span style="color: #000000;">php xdebug_start_code_coverage( XDEBUG_CC_UNUSED </span>|<span style="color: #000000;"> XDEBUG_CC_DEAD_CODE ); </span>?>
void xdebug_stop_code_coverage( [int cleanup=true] )
停止代码覆盖分析
该函数停止收集信息,该信息在内存中会被清除。如果你传递“false”参数,则代码覆盖信息不会被清除而能让你再次使用 xdebug_start_code_coverage() 恢复信息收集。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
