开发者

Alternative conditional syntax (if-else) failing on PHP 5.3.0 (xampp)

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-els开发者_开发百科e, 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:

<?php if(condition): ?>
<?php else: ?>
<?php endif ?>

Update: You really should test your code with short_open_tag turned on, because the syntax error you see is what you would get if you had this code somewhere:

<? if(condition): ?>
<?php else: ?>
<?php endif ?>


Yes, PHP 5.3 allows for alternative syntax for control structures, including your conditional statements.

I would suggest trying to debug by replacing the alternative syntax with regular syntax in one or two places to see if it fixes the problem. If it does, then you know for sure what the issue is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜