tags:

views:

981

answers:

6

Hi All

I just installed php 5.3.1 in my linux server and now my old work which i used to write with tags is not working at all..

Please help me out.. How can i resolve this??

+21  A: 

Short tags are disabled by default. I do not recommend you to use short tags (<? ?> or <?= ?>). You should use the full length tags (<?php ?>).
However to enable short tags enable the setting called short_open_tag in the php.ini file.

Just to wrap up some reasons why you should not use it:

  • If you want to make your application portable, it might be that short open tags are not allowed on another server and hence your application is not working.
  • Short open tags will be removed in PHP 6.

Update: An interesting discussion about this can be read here: http://www.mail-archive.com/[email protected]/msg41839.html

And for the default behaviour:

------------------------------------------------
php.ini values : short_open_tag
------------------------------------------------

PHP 4, 5_0
 * Default behaviour   : on
 * php.ini-dist        : on
 * php.ini-recommended : on

PHP 5_1, 5_2:
 * Default behaviour   : on
 * php.ini-dist        : on
 * php.ini-recommended : off

PHP 5_3:
 * Default behaviour   : on
 * php.ini-development : off
 * php.ini-production  : off

And the reason of discouraging short open tags:

This directive determines whether or not PHP will recognize code between
<? and ?> tags as PHP source which should be processed as such. It's been
recommended for several years that you not use the short tag "short cut" and
instead to use the full <?php and ?> tag combination. With the wide spread use of XML and use of these tags by other languages, the server can become easily
confused and end up parsing the wrong code in the wrong context. But because
this short cut has been a feature for such a long time, it's currently still
supported for backwards compatibility, but we recommend you don't use them.

Note also this declined RFC about short open tags for templates: http://wiki.php.net/rfc/shortags

Felix Kling
According to http://php.net/manual/en/ini.core.php, the default is "1", which sounds to me like enabled. I'd expect it to be disabled by default as well, though.
OregonGhost
@OregonGhost: Well es described here:http://stackoverflow.com/questions/1386620/php-echo-vs-php-short-tags *Actually, in the php.ini-production file provided with PHP 5.3.0, they are disabled by default* I guess from 5.3 on it is turned of by default.
Felix Kling
@OregonGhost: you are correct, but almost always an example configuration is supplied which will override the built-in defaults and choose appropriate settings. I believe php.ini-recommended sets them to off (although could not be certain without checking).
Splash
Just as another opinion, there is no single reason to avoid extremely useful `<?= ?>` syntax. And as of php6 it is just not true. Stop spreting this wild rumor
Col. Shrapnel
@Col Use <?php echo ?> instead of <?= ?>. Like many others I too have had problems with short tags. You never know where your code is going to be ran, so on the safe side, use <?php echo ?> The few extra bytes won't kill you :)
AntonioCS
@AntonioCS So what? I've heard of your problems already. I just stated that there is another point of view, based on the prcatical experience, not rumors. What if I do know where my code is going to be ran?
Col. Shrapnel
@Col. Shrapnel: Do you have a source that states that it is not true? From the information I have it seems that it is at least deprecated.
Felix Kling
Do **you** have a source that states that it is true? From the same discussion you linked above you have no less than Rasmus's own words "we decided not to remove them in PHP 6".
Col. Shrapnel
@Col. Shrapnel: Ok I think so far I will stick with this http://stackoverflow.com/questions/2413661/php6-is-short-open-tag-removed-or-deprecated-or-neither anyway, why didn't you come up with this? I can only tell what I know. Now I had to search for a confirmation that you are right although you could have just give it me. That is all I asked for. And that is why I think that you were not sure about this either. Otherwise you could have just said "here read this" and the discussion would have been over.
Felix Kling
@Col. How is <?= extremely useful? It's just as useful as <?php echo. Perhaps you meant extremely convenient?
Mike B
@Col. Shrapnel: I mean if obviously a lot people believe that it is going to be removed in PHP6, why didn't you provide a reliable source that this is not the case?
Felix Kling
Oh no, don't tell me of things in which a lot people do believe :)
Col. Shrapnel
Short tags aren't deprecated and not going to be removed. There are different opinions about usage of <?= - some recommend it, some don't. But there's very little reason to remove <?= - it doesn't help anything.
StasM
A: 

maybe your new configuration doesnt alllow short tags. Just use <?php ?>. It is better practise anyway.

If you still want to use them you can short_open_tag directive. Also bear in mind that won't work if you have short tags disabled.

The main reason for this is so you can use inline Xml tags.

Sinan
Not much a reason.
Col. Shrapnel
Actually if your code is going to run on other servers that you don't have control. Using <?php ?> will ensure portability.
Sinan
This *can* be a reason. But for one's own judgement, not strict recommendation. And actually most of code is written not for widespread. And there is a wide choice of template systems. And if someone uses PHP as a template system, using long tags is just ridiculous. Just choose another template system and forget this question at all
Col. Shrapnel
+4  A: 

Looks like you got short_open_tags set to "Off" in your php.ini file. Try setting it to "On" and restart apache.

Yo-L
A: 

You most likely need to turn on short tags in your PHP configuration file. Without knowing your configuration, I couldn't say where you'd find it, but you're looking for php.ini (most likely somewhere like /etc/php.ini).

In there, the setting you are after is short_open_tags. See here for all core configuration settings for PHP. However as others have mentioned, using short tags might not be the best strategy. Here is a good discussion of the reasons (for and against).

Splash
Good discussion with false reasons.
Col. Shrapnel
@Col. Shrapnel: How so? I tend to always favour long tags over short tags for some of the reasons described there. To be honest I think its at least partially down to personal preference. As long as you are aware of the implications either way, you can use what you want.
Splash
I am not talking of coding preferences now, I am talking of false rumors.
Col. Shrapnel
A: 

Hi all ,

Thanks...

I turn on the short_open_tags in config.

But why tags are more likely to use.

dhvani
A: 

Sounds like @Col. Shrapnel has an awful lot to lose if short tags are outlawed.

lancemonotone