View Issue Details

IDProjectCategoryView StatusLast Update
0001448XdebugCode Coveragepublic2017-07-22 08:28
Reporternickel715 Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
PlatformLinuxOSDebianOS Version8
Product Version2.5.1 
Summary0001448: Line covered even though not all
Description

I'm not sure if xdebug code coverage is intended to detect this, but I like to write php code like this:
!empty($var) && doSomething($var);

unfortunately this line is covered event though doSomething gets not executed.

Steps To Reproduce

I provide some example code to reproduce it

TagsNo tags attached.
Attached Files
test.php (664 bytes)   
<?php

function doSomething($param) {
    echo $param; #4
}                #5

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
!empty($var) && doSomething($var);  #8
$data = xdebug_get_code_coverage(); #9
xdebug_stop_code_coverage();

print_r($data);

/*
[test.php] => Array
(
    [8] => 1
    [9] => 1
)
*/

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
$var = 'hello';                     #23
!empty($var) && doSomething($var);  #24
$data = xdebug_get_code_coverage(); #25
xdebug_stop_code_coverage();

print_r($data);

/*
[test.php] => Array
(
    [4] => 1
    [5] => 1
    [23] => 1 
    [24] => 1
    [25] => 1
)
*/

test.php (664 bytes)   
Operating SystemLinux
PHP Version7.1.5-7.1.9

Activities

derick

2017-07-22 08:28

administrator   ~0004380

Although "doSomething" doesn't get executed, the !empty is executed. Xdebug can't really tell the difference as PHP just provides line numbers - and some of this line is executed.

So this is how it correctly works.

Issue History

Date Modified Username Field Change
2017-06-08 15:59 nickel715 New Issue
2017-06-08 15:59 nickel715 File Added: test.php
2017-07-22 08:28 derick Note Added: 0004380
2017-07-22 08:28 derick Status new => resolved
2017-07-22 08:28 derick Resolution open => no change required
2017-07-22 08:28 derick Assigned To => derick