View Issue Details

IDProjectCategoryView StatusLast Update
0001405XdebugCode Coveragepublic2017-03-10 13:16
Reporterexussum Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionnot fixable 
PlatformLinuxOSUbuntuOS Version16.10
Product Version2.5.1 
Summary0001405: Continue is covered incorrectly
Description

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

foreach([1,2] as $value) {
if (false) {
continue;
}
}

$cc = xdebug_get_code_coverage();
ksort($cc);
var_dump(array_slice($cc, 0, 1));
xdebug_stop_code_coverage(false);

the var dump above should be empty as you cant run the continue (if false prevents it being run)

Currently you get
int(1)

Steps To Reproduce

Run the above script

TagsNo tags attached.
Attached Files
broken.php (255 bytes)
Operating System
PHP Version7.1.0-7.1.4

Activities

exussum

2017-03-10 12:45

reporter   ~0004228

The copy paste was incorrect, use the file instead! sorry

derick

2017-03-10 12:50

administrator   ~0004229

I can't reproduce this:

derick@singlemalt:~ $ cat /tmp/1405.php
<?php
foreach([1,2] as $value) {
if (false) {
continue;
}
}

$cc = xdebug_get_code_coverage();
ksort($cc);
var_dump($cc);
xdebug_stop_code_coverage(false);

derick@singlemalt:~ $ php -v
PHP 7.1.3-dev (cli) (built: Feb 21 2017 14:55:35) ( NTS DEBUG )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans
[PHP: 7.1.3-dev ]

derick@singlemalt:~ $ php /tmp/1405.php
/tmp/1405.php:10:
array(0) {
}
[PHP: 7.1.3-dev ]

exussum

2017-03-10 12:53

reporter   ~0004230

PHP 7.0.15-0ubuntu0.16.10.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.15-0ubuntu0.16.10.4, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0-dev, Copyright (c) 2002-2017, by Derick Rethans

Is my version if you run the file rather than the code

it should have been

<?php

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

foreach([1,2] as $value) {
if (false) {
continue;
}
}

$cc = xdebug_get_code_coverage();
ksort($cc);
var_dump(current($cc)[7]);
xdebug_stop_code_coverage(false);

Which is in the file

exussum

2017-03-10 12:54

reporter   ~0004231

scott@PC147:/tmp$ php -v
PHP 7.0.15-0ubuntu0.16.10.4 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.15-0ubuntu0.16.10.4, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.6.0-dev, Copyright (c) 2002-2017, by Derick Rethans
scott@PC147:/tmp$ php broken.php
/tmp/broken.php:14:
int(1)
scott@PC147:/tmp$ cat broken.php
<?php

xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

foreach([1,2] as $value) {
if (false) {
continue;
}
}

$cc = xdebug_get_code_coverage();
ksort($cc);
var_dump(current($cc)[7]);
xdebug_stop_code_coverage(false);

To follow a similar flow as yours

derick

2017-03-10 13:16

administrator   ~0004232

OK, I can now reproduce this, but I can not fix it.

PHP unfortunately doesn't reset the line numbers for some of the generated code:

6 9 > EXT_STMT
10 > JMPZ <false>, ->13
7 11 > EXT_STMT
12 > JMP ->8
13 > > JMP ->8
14 > FE_FREE $3

The JMP in line 12 (and line 13) is generated for line 7, and not 8. This is something that needs to be fixed in PHP itself: http://bugs.php.net

Issue History

Date Modified Username Field Change
2017-03-10 12:44 exussum New Issue
2017-03-10 12:44 exussum File Added: broken.php
2017-03-10 12:45 exussum Note Added: 0004228
2017-03-10 12:50 derick Note Added: 0004229
2017-03-10 12:50 derick Assigned To => derick
2017-03-10 12:50 derick Status new => feedback
2017-03-10 12:53 exussum Note Added: 0004230
2017-03-10 12:53 exussum Status feedback => assigned
2017-03-10 12:54 exussum Note Added: 0004231
2017-03-10 13:16 derick Note Added: 0004232
2017-03-10 13:16 derick Status assigned => resolved
2017-03-10 13:16 derick Resolution open => not fixable