Why Xdebug function xdebug_get_code_coverage() return detail coverage information only once?

19 Views Asked by At

The Xdebug documentation states that when xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK); is set, the xdebug_get_code_coverage() function will return a value for each line, which could be -1, 1, or -2, along with detailed branch information. However, this information is only returned for the first request after the Apache server starts.

Here is my test code:

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE|XDEBUG_CC_BRANCH_CHECK);

function bye(){
    echo "Bye World\n";
}
function hello(){
    echo "Hello World\n";
}
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'd like to know why the second request and after requests return not as the first request.

0

There are 0 best solutions below