|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-12-12 13:12 UTC] rkenny at mke dot catalystwms dot com
The following will generate a parse error:
<? if ($var == "foo") { ?> <html>some stuff</html> <? } ?>
<? else if ($var == "bar" ) { ?> <html>other stuff</html> <? } ?>
But this works without error:
<? if ($var == "foo") { ?> <html>some stuff</html>
<? } else if ($var == "bar" ) { ?> <html>other stuff</html>
<? } ?>
Any help appreciated.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 08 20:00:02 2026 UTC |
This behavior is by design. The PHP closing tag ?> generates an implicit ; (semicolon), and thus, terminates any statement. For instance: <?php print "foo" ?> will work, because the closing tag will implicitly close the print statement. In your case, when you use <? } ?> to close your IF block, you're also terminating the entire statement, and thus, you cannot use 'ELSE' afterwards: if (...) { ... }; else if { // <-- invalid! ... }