iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register

Go Back   WebForumz.com > Blogs > alexgeek
Register All Albums Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

Why shouldn't I use PHP short tags?

Posted January 30th, 2008 at 03:37 PM 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
Oh dang, the url looks like "why shouldnt I use PHP" now.
permalink
Posted January 30th, 2008 at 03:37 PM by alexgeek alexgeek is offline
Old
LOL
Why not alex ?
lol
permalink
Posted January 30th, 2008 at 04:24 PM by simonb simonb is offline
Old
It should be just "PHP Short Tag"
permalink
Posted January 30th, 2008 at 09:12 PM 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 January 30th, 2008 at 11:27 PM 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 January 31st, 2008 at 08:46 AM by TheSealPortalTeam TheSealPortalTeam is offline
Old
Quick fix:
Find and replace "<? " (notice the space after the the ?) with "<?php "
permalink
Posted January 31st, 2008 at 03:08 PM by alexgeek alexgeek is offline
 
Recent Blog Entries by alexgeek

Search Engine Optimization by vBSEO 3.2.0 RC8