1

I had to made some changes to an old PHP-Project (with very poor code quality...) which runs on an PHP 5.3 server.

So I've downloaded the project and tried to run it locally (xampp with PHP 5.3) and I ende up with an error:

Parse error: syntax error, unexpected '}' in somefile.php on line 74

I've noticed that in this file the tags

<?php ?>

and

<? ?>

were mixed all over the place.

After some trial and error with replacing <? with <?php , I was able to get it working, but I would like to know what is causing this trouble.

user2345998
  • 649
  • 13
  • 31
  • 5
    The short tag can be disabled on a server. It is best practice to NOT use the short tag for this reason... – Blaatpraat Jun 22 '15 at 08:44
  • 3
    You need to change the setting in `php,ini` `short_open_tag=On` [read this](http://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags) – FatalError Jun 22 '15 at 08:45
  • But the old project has short open tags. – RN Kushwaha Jun 22 '15 at 08:46
  • 1
    @RNKushwaha it has, but the question is why it suddenly works after changing the short tag to the full tag. The answer can be that short tags are disabled by default nowadays... – Blaatpraat Jun 22 '15 at 08:47
  • @Blaatpraat Then there is no need to say `NOT use the short tag for this reason` if code is old. Its already there. – RN Kushwaha Jun 22 '15 at 08:49
  • your php would not be enabled for short tags. not a big issue open your php.ini file located in your wamp or xamp folder and change short tags value to `On` from `off` and restart server – Meenesh Jain Jun 22 '15 at 08:49
  • @RNKushwaha That's just advice for future code, and for other people reading this. – Blaatpraat Jun 22 '15 at 08:51
  • In latest version of PHP short tag are enabled by default. If you are using old version enable it from php.ini and restart apache server. – Praveen D Jun 22 '15 at 08:52
  • Short open tags are simply disabled by default in PHP 5.3. AFAIK – Felix Kling Jun 22 '15 at 08:52
  • incredible, I wrote that post, went to toilett and it got tons if comments in less then 3 minutes ^^ Thanks to all, short_open_tag=On works! – user2345998 Jun 22 '15 at 08:53
  • 1
    @PraveenD the short echo tag is enabled by default, the short tag isn't. – Blaatpraat Jun 22 '15 at 08:53
  • @PraveenD thx for this information - this was confusing me because = was used very often, so I thought short tags are working... – user2345998 Jun 22 '15 at 08:58

1 Answers1

2

Set

short_open_tag=On

in php.ini

And restart your Apache server

Malay M
  • 1,659
  • 1
  • 14
  • 22