note 85083 deleted from control-structures.break by peehaa
| From: | peehaa@php.net | Date: | Wed, 22 Feb 2017 09:35:43 +0000 |
| Subject: | note 85083 deleted from control-structures.break by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208791@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
The previous note has a somewhat stupid author: why didn't you put an example?
If I got it right, "case"s in "switch"es always need a "break".
So this switch ...
<?php
switch ( $i ) {
case '1': // Works
echo "$i=1";
break;
case '2': // Works
require( 'include1.inc' );
break;
case '3': // Doesn't work
require( 'include2.inc' );
break;
case '4': // Doesn't work, same reason
require( 'include2.inc' );
default: // Works
echo "$i";
}
?>
... has a problem in case "4" in that it doesn't have a "break" and this
file...
include2.inc:
<?php
echo "$i";
break;
?>
... has a problem in that it has a "break" that is not in a "control structure"
(like while, for...).
In the same way, although "include2.inc" is "include"d (obvioulsy) in the
<?php ?> script (of main.php), it still need another <?php ?> to wrap its content.
Likewise,
main.php
<?php
echo "<div>This div is generated by php</div>\n";
include 'file.php'; ?>
echo "<div>This div is also generated by php</div>\n";
file.php:
<div>This is an old static HTML div.</div>
... doesn't require "file.php" content to start with "?>" (exit php) and
end with "<?php" (go back to line 3 of main.php). This would FAIL.
(See strange structure ALWAYS fail"?>!)
Does this really need documentation?