#42644 [NEW]: For loop comma documentation wrong

From: Date: Wed, 12 Sep 2007 15:43:43 +0000
Subject: #42644 [NEW]: For loop comma documentation wrong
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6@lists.php.net to get a copy of this message
From: steve dot seear at uk dot ibm dot com Operating system: Windows PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: For loop comma documentation wrong Description: ------------ The for loop documentation page at http://uk3.php.net/manual/en/control-structures.for.php states that "Comma separated expressions in expr2 are treated similarly to being separated by the || operator." The supplied code shows that this is not the case. According to the documentation, all the loops in the code fragment should iterate twice, whereas actually, loop 2 only iterates once. For comma separated conditions, it appears that only the last condition in the comma separated list is tested. Reproduce code: --------------- <?php // comma operator in condition for ($a = $b = 0; $a < 1, $b < 2; $a++, $b++) { echo "loop 1, iteration $a\n"; } echo "\n"; for ($a = $b = 0; $b < 2, $a < 1; $a++, $b++) { echo "loop 2, iteration $a\n"; } echo "\n"; // || operator in condition for ($a = $b = 0; $a < 1 || $b < 2; $a++, $b++) { echo "loop 3, iteration $a\n"; } echo "\n"; for ($a = $b = 0; $b < 2 || $a < 1; $a++, $b++) { echo "loop 4, iteration $a\n"; } echo "\n"; ?> Expected result: ---------------- loop 1, iteration 0 loop 1, iteration 1 loop 2, iteration 0 loop 2, iteration 1 loop 3, iteration 0 loop 3, iteration 1 loop 4, iteration 0 loop 4, iteration 1 Actual result: -------------- loop 1, iteration 0 loop 1, iteration 1 loop 2, iteration 0 loop 3, iteration 0 loop 3, iteration 1 loop 4, iteration 0 loop 4, iteration 1 -- Edit bug report at http://bugs.php.net/?id=42644&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42644&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42644&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42644&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42644&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42644&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42644&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42644&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42644&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42644&r=support Expected behavior: http://bugs.php.net/fix.php?id=42644&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42644&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42644&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42644&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42644&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42644&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42644&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42644&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42644&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42644&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42644&r=mysqlcfg

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