Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/200323--/
Share on other sites

<? 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.

Link to comment
https://forums.phpfreaks.com/topic/200323--/#findComment-1051282
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/200323--/#findComment-1051286
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.