Search code examples
phpparse-error

Working PHP 5.2 code yields very frustrating PHP 5.3 parse errors that I cannot explain, help needed


The following code

<?php
try
{
    $var=0;
}
    catch(Exception $e)
{
    $var=1;
}
?>

in index.php yields

Parse error: syntax error, unexpected '{' in /home/site/public_html/index.php on line 3

The code is working on PHP 5.2.8, Zend Engine 2.2.0, Apache 2.2.21 (test server), but throws the parse error on PHP 5.3.3, Apache 1.3.42 (production machine!). Of course the actual code is more complex, but I reduced it to a bare minimum as above, which throws the parse error, too.

As you can imagine this is extremely frustrating, it should be such a straight forward thing.

I tried looking for hidden special chars in the source, there are none. There are other odd parse errors across the code, which I can see if I comment out the above. It really is weird.

Please suggest something, I'm at my wit's end, I don't know what to to with this. Let me know what other information you need.

Many thanks!


Solution

  • maybe you forgot to append a semi colon before the opening curly braces. Or you are running a php version < 5.0