php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57110 Code coverage discrepancies using if-statement without curly braces
Submitted: 2006-06-23 21:31 UTC Modified: 2007-07-13 08:03 UTC
From: skettler@php.net Assigned:
Status: Not a bug Package: Xdebug (PECL)
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: skettler@php.net
New email:
PHP Version: OS:

 

 [2006-06-23 21:31 UTC] skettler@php.net
Description:
------------
Using xdebug CVS as of 2006-06-24 00:00 UTC, but having the same problem using the latest beta.

When using if-statements that do not contain curly braces on their true/false-blocks, code coverage information is inaccurate. 

When using the same if-statements using curly braces, code coverage information is just fine.

Reproduce code:
---------------
<?php

xdebug_start_code_coverage();

if (false)      // wrongly marked not executed
    $a = 1;     // wrongly marked executed
else 
    $a = 2;     // wrongly marked not executed

if (true)       // wrongly marked not executed
    $a = 1;     // correctly marked executed
else 
    $a = 2;     // correctly marked not executed

if (false) {    // correctly marked executed
    $a = 1;     // correctly marked not executed
}
else {
    $a = 2;     // correctly marked executed
}

if (true) {     // correctly marked executed
    $a = 1;     // correctly marked executed
}
else {
    $a = 2;     // correctly marked not executed
}

var_dump(xdebug_get_code_coverage());

?>


Expected result:
----------------
array
  '.../coverage.php' => 
    array
      5 => 1
      8 => 1
      10 => 1
      11 => 1
      15 => 1
      19 => 1
      22 => 1
      23 => 1
      24 => 1
      29 => 1


Actual result:
--------------
array
  '.../coverage.php' => 
    array
      6 => 1
      11 => 1
      15 => 1
      19 => 1
      22 => 1
      23 => 1
      24 => 1
      29 => 1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-24 15:53 UTC] skettler@php.net
I've narrowed it down a bit:

<?php

if (true)
    $a = 1;

?>

produces the following opcodes:

ZEND_EXT_STMT
ZEND_JMPZ
ZEND_ASSIGN
ZEND_JMP

whereas

<?php

if (true) {
    $a = 1;
}

?>

produces:

ZEND_EXT_STMT
ZEND_JMPZ
ZEND_EXT_STMT
ZEND_ASSIGN
ZEND_JMP

Looks like PHP inconsistently omits ZEND_EXT_STMT in certain constellations (as you already noted in your ChangeLog).

Do we really have to override all possible opcodes or is there another way to correctly get full code coverage information?
 [2007-07-13 08:03 UTC] derick@php.net
This is the wrong place for Xdebug bug reports, please go to http://bugs.xdebug.org. (Your issue might already be fixed, so please try the latest version (from CVS) first).
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 05:01:23 2020 UTC