As the Xdebug documents, when set xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK);
. xdebug_get_code_coverage()
will return value for each line whether -1,1,-2,and detail branch information. But it only return when the first request after the Apache server started.
Here is my test code:
<?php
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE|XDEBUG_CC_BRANCH_CHECK);
function bye(){
echo "Bye Worldn";
}
function hello(){
echo "Hello Worldn";
}
hello();
var_dump(xdebug_get_code_coverage());
?>
After the first request, the result is:
Hello World
array(1) {
["/var/www/html/index.php"]=>
array(2) {
["lines"]=>
array(6) {
[5]=>
int(-1)
[6]=>
int(-1)
[8]=>
int(1)
[9]=>
int(1)
[10]=>
int(1)
[12]=>
int(1)
}
["functions"]=>
array(2) {
["hello"]=>
array(2) {
["branches"]=>
array(1) {
[0]=>
array(7) {
["op_start"]=>
int(0)
["op_end"]=>
int(3)
["line_start"]=>
int(8)
["line_end"]=>
int(9)
["hit"]=>
int(1)
["out"]=>
array(1) {
[0]=>
int(2147483645)
}
["out_hit"]=>
array(1) {
[0]=>
int(0)
}
}
}
["paths"]=>
array(1) {
[0]=>
array(2) {
["path"]=>
array(1) {
[0]=>
int(0)
}
["hit"]=>
int(1)
}
}
}
["bye"]=>
array(2) {
["branches"]=>
array(1) {
[0]=>
array(7) {
["op_start"]=>
int(0)
["op_end"]=>
int(3)
["line_start"]=>
int(5)
["line_end"]=>
int(6)
["hit"]=>
int(0)
["out"]=>
array(1) {
[0]=>
int(2147483645)
}
["out_hit"]=>
array(1) {
[0]=>
int(0)
}
}
}
["paths"]=>
array(1) {
[0]=>
array(2) {
["path"]=>
array(1) {
[0]=>
int(0)
}
["hit"]=>
int(0)
}
}
}
}
}
}
But when do the second request and after requests, the result become:
Hello World
array(1) {
["/var/www/html/index.php"]=>
array(2) {
["lines"]=>
array(4) {
[8]=>
int(1)
[9]=>
int(1)
[10]=>
int(1)
[12]=>
int(1)
}
["functions"]=>
array(0) {
}
}
}
I wonder why the second request and after requests return not as the first request.