Merdok Posted April 30, 2010 Share Posted April 30, 2010 At university my tutor told me that I should always use <?php instead of <?, I have blindly followed this rule for years now but, like many other things he taught me, he never really gave me a reason why. Recently I found out that a few other things he told me were not quite true (or at least very outdated) so now I am wondering if this is true. I like to seperate my code from my HTML as much as possible so I often will have blocks of HTML and then one line of PHP, its not a BIG deal for me to type <?php out every time but if I can just type <? and have the exact same effect then I might as well. Can someone tell me if it is ok to use this and if not, why not. Quote Link to comment https://forums.phpfreaks.com/topic/200323--/ Share on other sites More sharing options...
premiso Posted April 30, 2010 Share Posted April 30, 2010 <? is used when short tags are turned on in the php.ini. It is not wise to use them as they can be turned off. That is why you should generally always use <?php and type the extra 3 characters. As doing that you ensure that your script will work (at least tag wise) on any system running php and you will not have to make mundane updates to it, or have issues when upgrading to a new system or switching hosts etc. Quote Link to comment https://forums.phpfreaks.com/topic/200323--/#findComment-1051282 Share on other sites More sharing options...
Merdok Posted April 30, 2010 Author Share Posted April 30, 2010 Ah that makes sense... ok I'll continue to write it in full. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/200323--/#findComment-1051284 Share on other sites More sharing options...
cags Posted April 30, 2010 Share Posted April 30, 2010 As stated by premiso it's purely for portability, if you will always have full control over the production environment there is no negative effect. You can also use... <?= 'something' ?> // in place of <?php echo 'something'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/200323--/#findComment-1051285 Share on other sites More sharing options...
Mchl Posted April 30, 2010 Share Posted April 30, 2010 Not only portability, but also short tags can interfere with XML if you're working with it. In majority of cases it's portability though. <?= shortcut is at this moment bind with short tags, but there have been some voices, thet these two will be split in future, which makes a lot of sense IMHO. Quote Link to comment https://forums.phpfreaks.com/topic/200323--/#findComment-1051286 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.