Doc #69853 [Nab]: break behavior unspecified when no argument is specified
Edit report at https://bugs.php.net/bug.php?id=69853&edit=1
ID: 69853
User updated by: chealer at gmail dot com
Reported by: chealer at gmail dot com
Summary: break behavior unspecified when no argument is
specified
Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
cmb, the sentence you quote is semantically invalid (there may be more than one current affected
structure).
As for the example, it cannot replace specification (as for any example). Besides, the break
statement you mention is in a single affected structure.
Thanks for reopening
Previous Comments:
------------------------------------------------------------------------
[2015-06-16 18:32:52] cmb@php.net
In my opinion, the documentation is pretty clear about that issue:
| break ends execution of the current for, foreach, while,
| do-while or switch structure.
Furthermore line 5 of the example is:
| break; /* You could also write 'break 1;' here. */
------------------------------------------------------------------------
[2015-06-16 18:14:56] chealer at gmail dot com
Apologies, the result is the same, but the proper test should have read:
<?php
foreach(array(1, 2) as $iteration) {
var_dump($iteration);
foreach (array(1) as $dummy) {
break;
}
}
?>
------------------------------------------------------------------------
[2015-06-16 18:12:52] chealer at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/control-structures.break
---
"break accepts an optional numeric argument which tells it how many nested enclosing structures
are to be broken out of."
The documentation does not specify what happens if break's optional is not provided. Therefore,
the effect of a "break;" statement inside several concerned structures (as happens at the
end of the example) is unspecified. As of PHP 5.4, the effect appears to be that of "break
1;".
Comment http://php.net/manual/en/control-structures.break.php#90308
confirms.
Test script:
---------------
<?php
foreach(array(1, 2) as $iteration) {
var_dump($iteration);
foreach (array() as $dummy) {
break;
}
}
?>
Actual result:
--------------
int 1
int 2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69853&edit=1
Thread (7 messages)