Doc #68430 [NEW]: Clarify continue page for semicolon issue

From: Date: Sun, 16 Nov 2014 21:50:16 +0000
Subject: Doc #68430 [NEW]: Clarify continue page for semicolon issue
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-11640@lists.php.net to get a copy of this message
From: slxception at gmail dot com Operating system: PHP version: Irrelevant Package: Documentation problem Bug Type: Documentation Problem Bug description:Clarify continue page for semicolon issue Description: ------------ From manual page: http://www.php.net/control-structures.continue The last segment of "Omitting the semicolon" should be changed to correctly address versions. While there may be a changelog after the example, it is obscure, and if future changes come up, it may be missed. Here's the old text: Omitting the semicolon after continue can lead to confusion. Here's an example of what you shouldn't do. <?php for ($i = 0; $i < 5; ++$i) { if ($i == 2) continue print "$i\n"; } ?> One can expect the result to be: 0 1 3 4 but this script will output: 2 because the entire continue print "$i\n"; is evaluated as a single expression, and so print is called only when $i == 2 is true. (The return value of print is passed to continue as the numeric argument.) And here's a suggested change: Omitting the semicolon after continue can lead to confusion. Here's an example of what you shouldn't do. <?php for ($i = 0; $i < 5; ++$i) { if ($i == 2) continue print "$i\n"; } ?> One can expect the result to be: 0 1 3 4 but this script will output in PHP versions before 5.4.0: 2 In PHP versions 5.4.0 or greater, this script will output: Fatal error: 'continue' operator with non-constant operand is no longer supported on line 5 because the entire continue print "$i\n"; is evaluated as a single expression, and so print is called only when $i == 2 is true. (The return value of print is passed to continue as the numeric argument.) -- Edit bug report at https://bugs.php.net/bug.php?id=68430&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68430&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68430&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68430&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68430&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68430&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68430&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68430&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68430&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68430&r=support Expected behavior: https://bugs.php.net/fix.php?id=68430&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68430&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68430&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68430&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68430&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68430&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68430&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68430&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68430&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68430&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68430&r=mysqlcfg

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