Doc #55822 [NEW]: elseif/else if opcode difference

From: Date: Fri, 30 Sep 2011 16:42:58 +0000
Subject: Doc #55822 [NEW]: elseif/else if opcode difference
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7284@lists.php.net to get a copy of this message
From:             
Operating system: Linux
PHP version:      5.3.8
Package:          Documentation problem
Bug Type:         Documentation Problem
Bug description:elseif/else if opcode difference

Description:
------------
---
From manual page: http://www.php.net/control-structures.elseif
---
It is worth explaining the difference in opcode generation using "elseif"
vs "else if" -- or at least the effect of using one over the other.

Specifically, I'm referring to using PHPUnit with XDebug, in order to get
code coverage for some code.  What I've noticed is that using "else if",
even if you fully test that branch, no code coverage is produced for that
condition line (the code coverage report just skips over the "else if .."
line, leaving one line unexecuted, while everything else is green). 
Replacing that line with "elseif" instead, produces full green code
coverage!

See the test script below, and the output from using vld
(http://pecl.php.net/package/vld) to show the difference in opcode
generation, wherein having the space between "else" and "if" causes the
opcode to report the wrong line number, and therefore something like
xdebug, which tracks what lines get executed, is unable to track the fact
that the line was executed, and there is no code coverage.

The difference between "elseif" and "else if" should not cause unit testing
code coverage reports to change behavior.  The only way to get proper code
coverage with this bug is to force the developer to use "elseif".

Test script and results can also be seen at:
https://php.privatepaste.com/f468504857

Test script:
---------------
space.php:
<?php
if($x)
{
  echo 0;
}
else if ($y)
{
  echo 1;
}
?>

nospace.php:
<?php
if($x)
{
  echo 0;
}
elseif ($y)
{
  echo 1;
}

$ php -dvld.active=1 space.php >space.vld
$ php -dvld.active=1 nospace.php >nospace.vld
$ diff -uN space.vld nospace.vld


-- 
Edit bug report at https://bugs.php.net/bug.php?id=55822&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=55822&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=55822&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=55822&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=55822&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55822&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=55822&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=55822&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=55822&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=55822&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=55822&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=55822&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=55822&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=55822&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=55822&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=55822&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55822&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=55822&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=55822&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=55822&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=55822&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=55822&r=mysqlcfg



Thread (3 messages)

« previous php.doc.bugs (#7284) next »