View Issue Details

IDProjectCategoryView StatusLast Update
0001284XdebugCode Coveragepublic2020-03-12 17:35
ReporterDominique Fournier Assigned Toderick  
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionno change required 
Product Version2.2.5 
Summary0001284: Opening braces are not counted in code coverage
Description

If the code is in form :
<?php
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);

function a($a) 
{
    echo $a * 2.5;
}

function b($count) 
{
    for ($i = 0; $i < $count; $i++) 
    {
        a($i + 0.17);
    }
}

b(6);
b(10);

var_dump(xdebug_get_code_coverage());

The result will not see the opening braces are not counted in the lines covered :
array(11) {
[4] =>
int(1)
[6] =>
int(1)
[7] =>
int(1)
[9] =>
int(1)
[11] =>
int(1)
[13] =>
int(1)
[14] =>
int(1)
[15] =>
int(1)
[17] =>
int(1)
[18] =>
int(1)
[20] =>
int(1)
}

There is no line 5, 10 and 12

TagsNo tags attached.
Operating System
PHP Version5.6.15-5.6.19

Activities

derick

2016-03-14 19:13

administrator   ~0003569

Hi!

this is not a bug. PHP simply sees no code on these lines itself either. Because there is no code, there is nothing to "cover".

Looking at it with VLD, you get:

Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /tmp/1284.php
function name: (null)
number of ops: 29
compiled vars: none
line #* E I O op fetch ext return operands

2 0 E > EXT_STMT
1 EXT_FCALL_BEGIN
2 BW_OR ~0 1, 2
3 SEND_VAL ~0
4 DO_FCALL 1 'xdebug_start_code_coverage'
5 EXT_FCALL_END
4 6 EXT_STMT
7 NOP
9 8 EXT_STMT
9 NOP
17 10 EXT_STMT
11 EXT_FCALL_BEGIN
12 SEND_VAL 6
13 DO_FCALL 1 'b'
14 EXT_FCALL_END
18 15 EXT_STMT
16 EXT_FCALL_BEGIN
17 SEND_VAL 10
18 DO_FCALL 1 'b'
19 EXT_FCALL_END
20 20 EXT_STMT
21 EXT_FCALL_BEGIN
22 EXT_FCALL_BEGIN
23 DO_FCALL 0 $4 'xdebug_get_code_coverage'
24 EXT_FCALL_END
25 SEND_VAR_NO_REF 6 $4
26 DO_FCALL 1 'var_dump'
27 EXT_FCALL_END
21 28 > RETURN 1

Function a:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename: /tmp/1284.php
function name: a
number of ops: 7
compiled vars: !0 = $a
line #* E I O op fetch ext return operands

4 0 E > EXT_NOP
1 RECV !0
6 2 EXT_STMT
3 MUL ~0 !0, 2.5
4 ECHO ~0
7 5 EXT_STMT
6 > RETURN null

End of function a

Function b:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 17, Position 2 = 10
Branch analysis from position: 17
Jump found. Position 1 = -2
Branch analysis from position: 10
Jump found. Position 1 = 7
Branch analysis from position: 7
Jump found. Position 1 = 4
Branch analysis from position: 4
filename: /tmp/1284.php
function name: b
number of ops: 19
compiled vars: !0 = $count, !1 = $i
line #* E I O op fetch ext return operands

9 0 E > EXT_NOP
1 RECV !0
11 2 EXT_STMT
3 ASSIGN !1, 0
4 > IS_SMALLER 0000002:0000001 !1, !0
5 EXT_STMT
6 > JMPZNZ 10 0000002:0000001, ->17
7 > POST_INC 0000002:0000002 !1
8 FREE 0000002:0000002
9 > JMP ->4
13 10 > EXT_STMT
11 EXT_FCALL_BEGIN
12 ADD 0000003:0000003 !1, 0.17
13 SEND_VAL 0000003:0000003
14 DO_FCALL 1 'a'
15 EXT_FCALL_END
14 16 > JMP ->7
15 17 > EXT_STMT
18 > RETURN null

End of function b

0.425branch: # 0; line: 2- 21; sop: 0; eop: 28; out1: -2
path #1: 0,
branch: # 0; line: 4- 7; sop: 0; eop: 6; out1: -2
path #1: 0,
branch: # 0; line: 9- 11; sop: 0; eop: 3; out1: 4
branch: # 4; line: 11- 11; sop: 4; eop: 6; out1: 17; out2: 10
branch: # 7; line: 11- 11; sop: 7; eop: 9; out1: 4
branch: # 10; line: 13- 14; sop: 10; eop: 16; out1: 7
branch: # 17; line: 15- 15; sop: 17; eop: 18; out1: -2
path #1: 0, 4, 17,
path 0000002: 0, 4, 10, 7, 4, 17,
2.9255.4257.92510.42512.9250.4252.9255.4257.92510.42512.92515.42517.92520.42522.925/tmp/1284.php:20:
array(1) {
'/tmp/1284.php' =>
array(11) {
[4] =>
int(1)
[6] =>
int(1)
[7] =>
int(1)
[9] =>
int(1)
[11] =>
int(1)
[13] =>
int(1)
[14] =>
int(1)
[15] =>
int(1)
[17] =>
int(1)
[18] =>
int(1)
[20] =>
int(1)
}
}

cheers,
Derick

Issue History

Date Modified Username Field Change
2016-03-11 15:48 Dominique Fournier New Issue
2016-03-14 19:13 derick Note Added: 0003569
2016-03-14 19:13 derick Status new => resolved
2016-03-14 19:13 derick Resolution open => no change required
2016-03-14 19:13 derick Assigned To => derick
2020-03-12 16:55 derick Severity minor => feature
2020-03-12 17:35 derick Category Feature/Change request => Code Coverage