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

I recently updated to xampp v1.7.2 which dumped PHP 5.3 on me. Along with that, all my httpd.confs and php.ini were destroyed (I took it for granted that this release would be updated like all previous xampp releases). Anyway, it took me a while to reconfigure all the services, but now I am facing a funny problem.

This self-employed CMS that I use in my workplace uses a lot of alternative conditional syntax if-else, i.e.

if( condition ): ?>
    <some html />
<?php else: ?>
    <some other html />
<?php endif;

      

This works well with PHP 5.2.x which came along with xampp 1.7.1 - and now blocks of code like this generate this error:

Parse error: syntax error, unexpected T_ELSE in ...

I haven't changed my script in any way - the same one used to work without restrictions in PHP 5.2.x.

So my question is, does PHP 5.3 allow such alternative conditions? Or do I need to include a hidden option in my config files?

Please note that I am not using shorttags, so they are not an issue here.

+2


source to share


2 answers


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 to see if one of the other new syntax elements is obfuscating 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 need to validate your code when enabled short_open_tag

, because the syntax error you are seeing is what you would get if you had this code somewhere:

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

      

+4


source


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



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

0


source







All Articles