php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8211 Incorrect Parsing of <? and ?> tags
Submitted: 2000-12-12 13:12 UTC Modified: 2000-12-19 08:40 UTC
From: rkenny at mke dot catalystwms dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: RedHat Linux 6.1 (kernel 2.2.16-
Private report: No CVE-ID: None
 [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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-19 08:40 UTC] zeev@php.net
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!
   ...
}
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 23:00:02 2026 UTC