I recently upgraded to xampp v1.7.2 which dumped PHP 5.3 on me. Along with that all my httpd.confs and php.ini’s got wiped out (I had taken it for granted that this release will be an upgrade like all the earlier xampp releases). Anyway, it took me a while to reconfigure all the services – but now I’ve run into a funny problem.
This self-written CMS that is used in my workplace uses a lot of the alternative conditional syntax for if-else, i.e.
if( condition ): ?>
<some html />
<?php else: ?>
<some other html />
<?php endif;
This used to work fine with PHP 5.2.x that came along with xampp 1.7.1 – and now suddenly such code blocks are producing this error:
Parse error: syntax error, unexpected
T_ELSE in …
I haven’t altered my script in any way – the same used to work absolutely without a hitch in PHP 5.2.x.
So my question is, does PHP 5.3 allow such alternative conditionals? Or do I have to turn on some hidden option in my config files?
Please note that I don’t use shorttags – so they aren’t an issue here.
Although the if/else syntax hasn’t changed in 5.3, many other parts of the syntax have. You should check the lines just before the else statement in question to see if one of the other new syntax features is confusing the parser.
If you can’t figure out where the problem is, you can always just start systematically deleting lines of code until you’re left with the following three lines:
Update: You really should test your code with
short_open_tagturned on, because the syntax error you see is what you would get if you had this code somewhere: