View Issue Details

IDProjectCategoryView StatusLast Update
0000948XdebugUncategorizedpublic2013-05-18 22:30
Reporterashnazg Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version2.2.2 
Summary0000948: Unused+DeadCode not returning (-2) because of nested IF
Description

Having an inner IF inside an outer IF results in two lines being returned as (-1) rather than (-2) in the xdebug_get_code_coverage() return array.

In my fooGood() method coverage, the regular behavior return of (-2) for the "} else {" line and the function end line "}", as expected.

In my fooBad() method coverage, the equivalent lines (ELSE and function close brace) get return values of (-1) instead. The expectation is that (-2) would be returned for both lines.

Steps To Reproduce
  1. php xdebugTest.php
  2. Expect array keys of 12 and 20 (the ELSEs) and 15 and 23 (the function close braces) to all be (-2).
  3. Actual result is that 12 and 15 show (-1). This behavior will disappear if you comment out the inner IF.
Additional Information

I discovered this behavior while trying to figure out why PHP_CodeCoverage (1.2 branch on github) was showing these lines as red unexecuted code rather than as white ignored lines. CodeCoverage uses both the UNUSED and DEAD_CODE flags and appears to expect (-2) values to be returned for the lines in question.

(https://github.com/sebastianbergmann/php-code-coverage/issues/160)

This behavior is evident in all 2.2 versions (2.2.2, 2.2.1, 2.2.0, 2.2.0rc2, 2.2.0rc1).

TagsNo tags attached.
Attached Files
xdebugTest.php (778 bytes)
Operating SystemWindows7
PHP Version5.4.7

Activities

derick

2013-05-18 22:30

administrator   ~0002475

There is no bug here. In the case without the nested "if", the code can never reach the closing function bracket if you do statical analysis of code paths. However, in the case with the nested if it is possible to hit this. Xdebug doesn't know that the two if ($args) do the same thing, as it does not do evaluation of "if" statements during its analysis. Therefore, the "} else {" on line 12 and the "}" on line 15 can theoretically (but not logically) be reached.
If you provide an "else" with a "return false" for the nested if, you see then that the closing brace can not be reached again.

Issue History

Date Modified Username Field Change
2013-05-13 20:49 ashnazg New Issue
2013-05-13 20:49 ashnazg File Added: xdebugTest.php
2013-05-18 22:30 derick Note Added: 0002475
2013-05-18 22:30 derick Status new => resolved
2013-05-18 22:30 derick Resolution open => no change required
2013-05-18 22:30 derick Assigned To => derick
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