Jump to content

any problem with just using <?


scarhand

Recommended Posts

It's not quite so black and white. Using short tags ( <? ) is perfectly acceptable in a controlled development environment. Short tags can be disabled though, and if you have no control over the settings of the production server, or if you're developing the script for use on several servers, then I suggest using full tags ( <?php )

Link to comment
Share on other sites

PHP manual states this:

 

Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.

 

Personally I don't see a reason to use short tags anywhere.

Link to comment
Share on other sites

It's not quite so black and white. Using short tags ( <? ) is perfectly acceptable in a controlled development environment. Short tags can be disabled though, and if you have no control over the settings of the production server, or if you're developing the script for use on several servers, then I suggest using full tags ( <?php )

 

I always code for redistribution. If someone wants to, or needs to read my code, I don't want them to know I'm breaking portability to save me the time of hitting php after the <?.

 

Sure, you don't think you'll ever use your code except on a server you control 100% of the time, so why not save the 0.5 seconds it takes to use the correct tags? What happens when your friend sends you an instant message telling you he's on a deadline with his boss riding him to get this project done fast, and he wants to borrow your image manipulation classes. what do you do? tell him no? go through and fix your short tags? tell him to make sure he has short tags enabled? what if he uses <?xml ?> in his scripts and he can't enable short tags because it breaks his xml? tell him to fix the tags himself?

 

The fact of the matter is, you're never 100% sure where your code will be used in the future. You don't know if you'll use the code yourself on hundreds of different projects and have to bother to turn on short tags EVERY time you code in a different server. You don't know if you'll redistribute your code. etc... It's better to take the TINY bit of effort it takes to type "php" than have it make you check every php.ini you code for in the future.

Link to comment
Share on other sites

Php.net made a blunder when they introduced a second tag that identifies the start of php code (in a lazy way attempt to save typing a few characters per page, which has cost many thousand's of more lost time to troubleshoot why code does not work when moved to a different server or when someone upgrades a server but forgets or does not know to turn on short_open_tag, then it ever saved in typing time) and then they made another blunder when that second tag could be turned off.

 

If there are two tags that define the start of what is code and one of them does not always work, or cannot be distinguished to be different from <?xml, you have screwed up.

 

Php6 is supposed to add a error if you mix <?php and <?/<?= in one file, so they are probably getting ready to depreciate short tags. The next step would be to remove them (I suspect the person who introduced <? is still on the php.net committee and once he is out, short tags will follow.)

 

No one should use short open tags. They are a bad idea.

Link to comment
Share on other sites

I like this quote from PHP 5 Certification Guide :D

 

Nobody quite understands why ASP tags were introduced—however, if you are so inclined you can turn on this optional configuration option, and you are free to use them.

 

Oh, and they also have this note right below:

 

Short tags, script tags and ASP tags are all considered deprecated and their use is strongly discouraged.

Link to comment
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.