php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68430 Clarify continue page for semicolon issue
Submitted: 2014-11-16 21:50 UTC Modified: 2014-11-19 15:26 UTC
From: slxception at gmail dot com Assigned: salathe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: slxception at gmail dot com
New email:
PHP Version: OS:

 

 [2014-11-16 21:50 UTC] 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.)



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-19 15:24 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=335197
Log: mention 5.4.0 in continue-missing-semicolon example (doc bug #68430)
 [2014-11-19 15:26 UTC] salathe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: salathe
 [2014-11-19 15:26 UTC] salathe@php.net
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.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 03:00:02 2026 UTC