views:

544

answers:

2

Hello, 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.

Thanks, m^e

A: 

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.

James Skidmore
Right! I'll do the same and get back to you shortly... :)
miCRoSCoPiC_eaRthLinG
Funny thing.. if I modify the code block to standard syntax, i.e. if( condition ) echo '<some html />' - it WORKS!!! But if that's the way to go, I've to sit back and modify thousands of lines of code... :S
miCRoSCoPiC_eaRthLinG
Could you post a snippet of the code where you changed it and it works? Also include a little bit before/after. Maybe I'll be able to spot something.
James Skidmore
Thanks for all the help :) Figured out a temp. fix.
miCRoSCoPiC_eaRthLinG
+1  A: 

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 ?>
too much php
Tried the same... and still getting the same error on 'else' line.
miCRoSCoPiC_eaRthLinG
You were right! It started working again when I turned short_open_tags On. So I must have misspelt the <?php to <? somewhere else in my code. I checked and rechecked this code-block thoroughly and couldn't find any instance in here. Anyway, my dev. platform is back - thanks to you :) Wonder if there's any easy way to check for the presence of shottags through all my project files..
miCRoSCoPiC_eaRthLinG
BTW, can you please point me to a page outlining all the syntax changes in this PHP ver? Thanks.
miCRoSCoPiC_eaRthLinG
For changes in 5.3, just see http://php.net/migration53 . You can search for short tags very easily - search for '<? ' or '<?$' or '<?[^p]', depending on whether or not you want to use grep / regex, etc.
too much php