View Issue Details

IDProjectCategoryView StatusLast Update
0001479XdebugCode Coveragepublic2017-11-01 22:54
Reportermorozov Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Summary0001479: The line containing a boolean value of an array element is not considered covered
Description

Using the same Xdebug version (2.5.5) but depending on the PHP version (5.6 or 7.1), the same line of code is or is not reported as covered.

It looks like it depends on the value type (only the boolean value has this issue while the integer one doesn't).

Steps To Reproduce

Consider the following PHP script:

<?php
xdebug_start_code_coverage();

$array = array(
'int' => 1,
'bool' => true,
);

var_dump(xdebug_get_code_coverage());
?>

$ php -v
PHP 5.6.31 (cli) (built: Sep 21 2017 13:13:29)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

$ php coverage.php
/home/morozov/coverage.php:10:
array(1) {
'/home/morozov/coverage.php' =>
array(4) {
[6] =>
int(1)
[7] =>
int(1)
[8] =>
int(1)
[10] =>
int(1)
}
}

$ php -v
PHP 7.1.9 (cli) (built: Sep 15 2017 19:44:50) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.9, Copyright (c) 1999-2017, by Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

$ php coverage.php
/home/morozov/coverage.php:10:
array(1) {
'/home/morozov/coverage.php' =>
array(2) {
[6] =>
int(1)
[10] =>
int(1)
}
}

TagsNo tags attached.
Operating System
PHP Version7.1.0-7.1.4

Activities

derick

2017-11-01 21:46

administrator   ~0004450

This is an improvement in PHP 7.1 - it has the array initialisation optimised from using 3 opcodes in PHP 5.6:

line #* E I O op fetch ext return operands

5 5 INIT_ARRAY 0000002:0000001 1, 'int'
6 6 ADD_ARRAY_ELEMENT 0000002:0000001 <bool>, 'bool'
7 7 ASSIGN !0, 0000002:0000001

To just one in PHP 7.1:

line #* E I O op fetch ext return operands

5 6 ASSIGN !0, <array>

Xdebug correctly shows there is no executable code at all on lines 6 and 7 with PHP 7.1 (use the XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE options to xdebug_start_code_coverage), which means there is nothing to fix here.

morozov

2017-11-01 22:54

reporter   ~0004451

Thank you for the explanation. Do I understand correctly that the resulting opcode references only one of the lines of the source code it was built from? So when the bytecode executed with code coverage enabled, the information about the source lines is unavailable.

Issue History

Date Modified Username Field Change
2017-10-10 21:18 morozov New Issue
2017-11-01 21:46 derick Note Added: 0004450
2017-11-01 21:46 derick Status new => resolved
2017-11-01 21:46 derick Resolution open => no change required
2017-11-01 21:46 derick Assigned To => derick
2017-11-01 22:54 morozov Note Added: 0004451