MantisBT - Xdebug
View Issue Details
0001541XdebugCode Coveragepublic2018-03-26 15:422018-12-06 15:33
theoboldt 
derick 
normalmajoralways
assignedopen 
LinuxUbuntu16.04.1
2.6.0 
 
7.0.25-7.0.29
0001541: switch/case case is not covered when using php-fpm php 7.0
When executing switch/case within a function, no case line of executed cases is marked as covered, except the following:
* The first line is marked as covered as expected
* The "default" case is marked as covered as expected

The lines are marked as covered as expected when the same file is executed via CLI using same php/xdebug version.

{code}
<?php

function a($option) {
    switch ($option) {
        case 'first':
            $option .= '_covered';
            break;
        case 'second':
            $option .= '_covered';
            break;
        case 'third':
            $option .= '_covered';
            break;
        default:
            $option .= '_covered';
            break;
    }
    return $option;
}

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

a('first');
a('second');
a('third');
a('default');

$coverage = xdebug_get_code_coverage();
xdebug_stop_code_coverage();


//EVALUATE (not part of proof)
print_r(
    [
        'phpversion(\'xdebug\')' => phpversion('xdebug'),
        'phpversion()'           => phpversion(),
        'php_sapi_name()'        => php_sapi_name()
    ]
);
print_r($coverage);
?>

{code}

When executing above code via CLI, following output is generated:
{code}
Array
(
    [phpversion('xdebug')] => 2.6.0
    [phpversion()] => 7.0.28-0ubuntu0.16.04.1
    [php_sapi_name()] => cli
)
Array
(
    [/intproj/users/erik/xdebug_coverage_issues/switch_case.php] => Array
        (
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => 1
            [9] => 1
            [10] => 1
            [11] => 1
            [12] => 1
            [13] => 1
            [15] => 1
            [16] => 1
            [18] => 1
            [23] => 1
            [24] => 1
            [25] => 1
            [26] => 1
            [28] => 1
        )

)

{code}

When executing above code via Apache 2 (Server API: FPM/FastCGI, PHP API: 20151012, PHP Extension: 20151012) the output differs significantly for line 8 and 11:
{code}
Array
(
    [phpversion('xdebug')] => 2.6.0
    [phpversion()] => 7.0.28-0ubuntu0.16.04.1
    [php_sapi_name()] => fpm-fcgi
)
Array
(
    [/intproj/users/erik/xdebug_coverage_issues/switch_case.php] => Array
        (
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => -1
            [9] => 1
            [10] => 1
            [11] => -1
            [12] => 1
            [13] => 1
            [15] => 1
            [16] => 1
            [18] => 1
            [23] => 1
            [24] => 1
            [25] => 1
            [26] => 1
            [28] => 1
        )
)

{code}
Execute provided using php 7.0.28 snipped via php-fpm and via cli as well, compare results
PHP7
? switch_case.php (827) 2018-03-26 15:42
https://bugs.xdebug.org/file_download.php?file_id=430&type=bug
Issue History
2018-03-26 15:42theoboldtNew Issue
2018-03-26 15:42theoboldtFile Added: switch_case.php
2018-03-26 15:48theoboldtTag Attached: PHP7
2018-11-15 10:54theoboldtNote Added: 0004724
2018-12-06 12:11derickNote Added: 0004749
2018-12-06 12:11derickAssigned To => derick
2018-12-06 12:11derickStatusnew => feedback
2018-12-06 15:21theoboldtNote Added: 0004750
2018-12-06 15:21theoboldtStatusfeedback => assigned
2018-12-06 15:33theoboldtNote Added: 0004753

Notes
(0004724)
theoboldt   
2018-11-15 10:54   
Still reproducible using xdebug 2.6.1.
(0004749)
derick   
2018-12-06 12:11   
Do you have opcache installed and enabled for the PHP-FPM install?
(0004750)
theoboldt   
2018-12-06 15:21   
> Do you have opcache installed and enabled for the PHP-FPM install?
In the provided examples, opcache was installed and enabled. I performed some tests now using PHP 7.0.32-0ubuntu0.16.04.1. It's worth to notice that the results slightly differ when having opcache enabled/disabled, but issue in general still exists:

Result having opcache enabled:
{code}
Array
(
    [phpversion('xdebug')] => 2.6.0
    [phpversion()] => 7.0.32-0ubuntu0.16.04.1
    [php_sapi_name()] => fpm-fcgi
)
Array
(
    [/intproj/users/erik/switch_case.php] => Array
        (
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => -1
            [9] => 1
            [10] => 1
            [11] => -1
            [12] => 1
            [13] => 1
            [15] => 1
            [16] => 1
            [18] => 1
            [23] => 1
            [24] => 1
            [25] => 1
            [26] => 1
            [28] => 1
        )
)
{code}

Result having opcache disabled:
{code}
Array
(
    [phpversion('xdebug')] => 2.6.0
    [phpversion()] => 7.0.32-0ubuntu0.16.04.1
    [php_sapi_name()] => fpm-fcgi
)
Array
(
    [/intproj/users/erik/switch_case.php] => Array
        (
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => -1
            [9] => 1
            [10] => 1
            [11] => -1
            [12] => 1
            [13] => 1
            [15] => 1
            [16] => 1
            [18] => 1
            [19] => -2
            [23] => 1
            [24] => 1
            [25] => 1
            [26] => 1
            [28] => 1
        )
)
{code}
(0004753)
theoboldt   
2018-12-06 15:33   
Also reproducible using php 7.2:

opcache enabled:
{code}
Array
(
    [phpversion('xdebug')] => 2.6.0
    [phpversion()] => 7.2.10-0ubuntu0.18.04.1
    [php_sapi_name()] => fpm-fcgi
)
Array
(
    [/intproj/users/erik/switch_case.php] => Array
        (
            [4] => 1
            [5] => -1
            [6] => 1
            [7] => 1
            [8] => -1
            [9] => 1
            [10] => 1
            [11] => -1
            [12] => 1
            [13] => 1
            [15] => 1
            [16] => 1
            [18] => 1
            [23] => 1
            [24] => 1
            [25] => 1
            [26] => 1
            [28] => 1
        )
)
{code}

opcache disabled:
{code}
Array
(
    [phpversion('xdebug')] => 2.6.0
    [phpversion()] => 7.2.10-0ubuntu0.18.04.1
    [php_sapi_name()] => fpm-fcgi
)
Array
(
    [/intproj/users/erik/switch_case.php] => Array
        (
            [4] => 1
            [5] => -1
            [6] => 1
            [7] => 1
            [8] => -1
            [9] => 1
            [10] => 1
            [11] => -1
            [12] => 1
            [13] => 1
            [15] => 1
            [16] => 1
            [18] => 1
            [19] => -2
            [23] => 1
            [24] => 1
            [25] => 1
            [26] => 1
            [28] => 1
        )
)
{code}