From: rjnewton at efn dot org
Operating system: Windows XP
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: Implies That 0 Evaluates True
Description:
------------
Current PHP manual [Tue Nov 22 00:57:49 2005] suggests under Language
Reference|Control Structures|while that while(0) keeps a loop in play
until a break condition occurs. This is the reverse of the actual case.
Reproduce code:
---------------
<?php
$i = 12;
$factor = 0.5;
$minimum_limit = 2;
do {
if ($i < 5) {
echo "i is not big enough\n";
break;
}
$i *= $factor;
if ($i < $minimum_limit) {
break;
}
echo "i is ok\n";
/* process i */
} while (0);
?>
Expected result:
----------------
Should make two full passes through the loop, the exit at the first if
statement of the third loop, since $i will then be 3, thus $ < 5 will
evaluate true. This is the behavior when while(1) is used as the control
condition.
Actual result:
--------------
using while(0):
D:\newtonj\PHPstuff>php hello.php
i is ok
using while(1):
D:\newtonj\PHPstuff>php hello.php
i is ok
i is ok
i is not big enough
--
Edit bug report at http://bugs.php.net/?id=36523&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36523&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36523&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36523&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36523&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36523&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36523&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36523&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36523&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36523&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36523&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36523&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36523&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36523&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36523&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36523&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36523&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36523&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36523&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36523&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36523&r=mysqlcfg