Doc #68430 [Opn->Csd]: Clarify continue page for semicolon issue
| From: | salathe@php.net | Date: | Wed, 19 Nov 2014 15:26:47 +0000 |
| Subject: | Doc #68430 [Opn->Csd]: Clarify continue page for semicolon issue | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11663@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68430&edit=1
ID: 68430
Updated by: salathe@php.net
Reported by: slxception at gmail dot com
Summary: Clarify continue page for semicolon issue
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
-Assigned To:
+Assigned To: salathe
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2014-11-19 15:24:33] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=335197
Log: mention 5.4.0 in continue-missing-semicolon example (doc bug #68430)
------------------------------------------------------------------------
[2014-11-16 21:50:15] slxception at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=68430&edit=1