View Issue Details

IDProjectCategoryView StatusLast Update
0001324XdebugUncategorizedpublic2016-07-07 10:00
Reportermunkie Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionnot fixable 
Product Version2.4.0 
Summary0001324: Not all line of array of class constants is covered with php7
Description

Given array of class constants is assigned to variable
Code coverage shows that only first line of array is covered on php7
But on php5 version all lines are covered

Tested against master branch (commit 5744af67332931df80b120b5796cd4425dfef0aa)

Steps To Reproduce

Run following script, should return OK

<?php

class Klass
{
const A = 'A';
const B = 'B';
const C = 'C';
}

xdebug_start_code_coverage();

$map = [
Klass::A,
Klass::B,
Klass::C,
];

xdebug_stop_code_coverage(false);
$coverage = xdebug_get_code_coverage();

$expected = [13 => 1, 14 => 1, 15 => 1, 16 => 1, 18 => 1];
echo ($expected === reset($coverage) ? 'OK' : 'ERROR') . "\n";
var_dump($coverage);

TagsNo tags attached.
Operating SystemUbuntu 16.04 LTS
PHP Version7.0.5-7.0.9

Activities

derick

2016-07-07 09:57

administrator   ~0003641

Last edited: 2016-07-07 10:00

Hi!

You're right, it indeed does not show any code on lines 14-17.

But unfortunately, I can't do anything about this. In PHP 7, the constant array is converted during parsing to a <array> node in the AST, and the only code that is run, is actually the assignment. If you look at it with VLD, it shows:

[code]
10 2 EXT_STMT
3 INIT_FCALL 'xdebug_start_code_coverage'
4 EXT_FCALL_BEGIN
5 DO_FCALL 0
6 EXT_FCALL_END
13 7 EXT_STMT
8 ASSIGN !0, <array>
18 9 EXT_STMT
10 INIT_FCALL 'xdebug_stop_code_coverage'
11 EXT_FCALL_BEGIN
12 SEND_VAL <false>
13 DO_FCALL 0
14 EXT_FCALL_END
[/code]

The ASSIGN on line 13 is the whole assignment.

PHP 5 did not have this optimisation, and hence runs code for each line:

[code]
10 2 EXT_STMT
3 EXT_FCALL_BEGIN
4 DO_FCALL 0 'xdebug_start_code_coverage'
5 EXT_FCALL_END
13 6 EXT_STMT
7 FETCH_CONSTANT 0000002:0000002 'Klass', 'A'
8 INIT_ARRAY 0000003:0000003 0000002:0000002
14 9 FETCH_CONSTANT 0000004:0000004 'Klass', 'B'
10 ADD_ARRAY_ELEMENT 0000003:0000003 0000004:0000004
15 11 FETCH_CONSTANT 0000017:0000005 'Klass', 'C'
12 ADD_ARRAY_ELEMENT 0000003:0000003 0000017:0000005
16 13 ASSIGN !0, 0000003:0000003
18 14 EXT_STMT
15 EXT_FCALL_BEGIN
16 SEND_VAL <bool>
17 DO_FCALL 1 'xdebug_stop_code_coverage'
18 EXT_FCALL_END
[/code]

cheers,
Derick

Issue History

Date Modified Username Field Change
2016-06-30 04:21 munkie New Issue
2016-07-07 09:57 derick Note Added: 0003641
2016-07-07 09:57 derick Status new => resolved
2016-07-07 09:57 derick Resolution open => not fixable
2016-07-07 09:57 derick Assigned To => derick
2016-07-07 09:58 derick Note Edited: 0003641
2016-07-07 10:00 derick Note Edited: 0003641
2016-07-31 12:36 derick Category Usage problems => Usage problems (Crashes)
2016-07-31 12:38 derick Category Usage problems (Crashes) => Usage problems (Wrong Results)
2020-03-12 16:35 derick Category Usage problems (Wrong Results) => Variable Display
2020-03-12 16:38 derick Category Variable Display => Uncategorized