Why shouldn't I use PHP short tags?
Firstly, the normal php tags are:
<?php code here ?>
<? 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:
<?php
$hai = "Oh hai";
echo $hai;
?>
be shortened to: (providing that $hai is already defined in the script)
<?=$hai; ?>
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.."
So there you go, don't use them!
And one side not, there was also a html style way of opening php tags with:
<script type="php"> code here </script>
There you go webforumz, my wisom. :idea1:
Comments
|
|
Oh dang, the url looks like "why shouldnt I use PHP" now.
|
Posted Jan 30th, 2008 at 18:37 by alexgeek
|
|
|
LOL
Why not alex ? lol |
Posted Jan 30th, 2008 at 19:24 by simonb
|
|
|
It should be just "PHP Short Tag"
|
Posted Jan 31st, 2008 at 00:12 by Monie
|
|
|
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.
|
Posted Jan 31st, 2008 at 02:27 by WebNinja
|
|
|
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 |
Posted Jan 31st, 2008 at 11:46 by TheSealPortalTeam
|
|
|
Quick fix:
Find and replace "<? " (notice the space after the the ?) with "<?php " |
Posted Jan 31st, 2008 at 18:08 by alexgeek
|
Post a Comment
|
Trackbacks
- 3D Chess in your browser! (Mar 14th, 2008)
- Asp.net C# (Feb 12th, 2008)
- Social Networking & Dating sites (Feb 7th, 2008)
- Why shouldn't I use PHP short tags? (Jan 30th, 2008)
- Ajax (Jan 12th, 2008)













