MantisBT - Xdebug
View Issue Details
0001601XdebugCode Coveragepublic2019-01-03 13:492019-01-05 08:52
exussum 
 
normalminoralways
newopen 
LinuxUbuntu 18.04
2.6.1 
 
7.2.5-7.2.9
0001601: Line shown as covered when not been run
Line shown as covered when not been run
<?php

function test() {
    foreach([1,2] as $a) {
        if (false) {
            try {
                echo "Try";
            } catch (Exception $e) {
                echo "Catch";
            }
        }
    }
}

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
test();
var_dump(xdebug_get_code_coverage());
xdebug_stop_code_coverage();



The catch line (line 9) is shown as covered, when its not.
Running the above script line 9 should show as -1, its showing as 1

I get the following.

/tmp/test.php:17:
array(1) {
  '/tmp/test.php' =>
  array(8) {
    [4] =>
    int(1)
    [5] =>
    int(1)
    [7] =>
    int(-1)
    [8] =>
    int(-1)
    [9] =>
    int(1)
    [13] =>
    int(1)
    [16] =>
    int(1)
    [17] =>
    int(1)
  }
}

xdebug 2.6.1 on php 5.6 works as expected,m it seems 7.0+ has this error
No tags attached.
? test.php (364) 2019-01-03 13:49
https://bugs.xdebug.org/file_download.php?file_id=455&type=bug
Issue History
2019-01-03 13:49exussumNew Issue
2019-01-03 13:49exussumFile Added: test.php
2019-01-03 13:50exussumNote Added: 0004794
2019-01-05 08:52exussumNote Added: 0004795

Notes
(0004794)
exussum   
2019-01-03 13:50   
Done some more checking, the if can be removed, its the loop and the catch which causes this
(0004795)
exussum   
2019-01-05 08:52   
Sorry can be closed just found the fix in PHP