Web Design and Development Forums

Go Back   Webforumz.com > Blogs > alexgeek

Welcome to Webforumz.com.
Register Now Register now!

Why shouldn't I use PHP short tags?

Posted Jan 30th, 2008 at 18:37 by alexgeek
A lot of people seem to use them but a lot of experienced PHP developers discourage the use of short tags for two main reasons.

Firstly, the normal php tags are:
Code:
<?php code here ?>
And the following are short tags:
Code:
<? code here ?>
<?=variable here ?>
<% %>

The first are for those too lazy to put php after <?.
The second it to quickly echo a variable. E.G, the following:
Code:
<?php
$hai 
"Oh hai";
echo 
$hai;
 
?>
Can
be shortened to: (providing that $hai is already defined in the script)
Code:
<?=$hai?>
Seems like something that would help? Think again.

The last of the short tags is ASP tags. God knows why they were put into PHP (It seems most experienced developers don't even know why) but they were. I've never had any reason to use these and therefore never had a problem with it, but maybe you would encounter problems when manipulating ASP code but not wishing to execute it.

Anyway.
The two main reasons not to use PHP short tags are
  • Some servers may not support PHP short tags, so script compatibility can only be achieved by going through all script and replacing with the proper PHP short tags.
  • Conflict with the XML opening tag. "<?xml.."
The latter I've had first hand experience with and I had to resort to pointlessly echo'ing out the "<?xml.." part rather than just putting it there.

So there you go, don't use them!

And one side not, there was also a html style way of opening php tags with:
HTML Code:
<script type="php">
code here
</script>
But these are pointless now. They were so that earlier html syntax highlighters could recognise PHP easily.

There you go webforumz, my wisom. :idea1:

Total Comments 6

Comments

Old
alexgeek's Avatar
Oh dang, the url looks like "why shouldnt I use PHP" now.
permalink
Posted Jan 30th, 2008 at 18:37 by alexgeek alexgeek is offline
Old
simonb's Avatar
LOL
Why not alex ?
lol
permalink
Posted Jan 30th, 2008 at 19:24 by simonb simonb is offline
Old
It should be just "PHP Short Tag"
permalink
Posted Jan 31st, 2008 at 00:12 by Monie Monie is offline
Old
I agree. If you're concerned about the time it takes to type "PHP", use copy & paste. You don't even have to use the keyboard if you know how to right-click.
permalink
Posted Jan 31st, 2008 at 02:27 by WebNinja WebNinja is offline
Old
TheSealPortalTeam's Avatar
Very interesting. Even through I usually don't use PHP, its always good to know when building small scripts here or there.
By the way, I fall victim to using short tags, so now I know why some of my code ceases to work.

Thanks
permalink
Posted Jan 31st, 2008 at 11:46 by TheSealPortalTeam TheSealPortalTeam is offline
Old
alexgeek's Avatar
Quick fix:
Find and replace "<? " (notice the space after the the ?) with "<?php "
permalink
Posted Jan 31st, 2008 at 18:08 by alexgeek alexgeek is offline
Post a Comment Post a Comment
Total Trackbacks 0

Trackbacks

Recent Blog Entries by alexgeek


Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 05:42.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59