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:
And the following are short tags:
The first are for those too lazy to put php after <?.
The second it to quickly echo a variable. E.G, the following:
Can
be shortened to: (providing that $hai is already defined in the script)
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
So there you go, don't use them!
And one side not, there was also a html style way of opening php tags with:
But these are pointless now. They were so that earlier html syntax highlighters could recognise PHP easily.
There you go webforumz, my wisom. :idea1:
Firstly, the normal php tags are:
Code:
<?php code here ?>
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;
?>
be shortened to: (providing that $hai is already defined in the script)
Code:
<?=$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:
HTML Code:
<script type="php"> code here </script>
There you go webforumz, my wisom. :idea1:
Total Comments 6
Comments
|
|
Oh dang, the url looks like "why shouldnt I use PHP" now.
|
Posted January 30th, 2008 at 03:37 PM by alexgeek
|
|
|
LOL
Why not alex ? lol |
Posted January 30th, 2008 at 04:24 PM by simonb
|
|
|
It should be just "PHP Short Tag"
|
Posted January 30th, 2008 at 09:12 PM 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 January 30th, 2008 at 11:27 PM 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 January 31st, 2008 at 08:46 AM by TheSealPortalTeam
|
|
|
Quick fix:
Find and replace "<? " (notice the space after the the ?) with "<?php " |
Posted January 31st, 2008 at 03:08 PM by alexgeek
|
Recent Blog Entries by alexgeek
- 3D Chess in your browser! (March 14th, 2008)
- Asp.net C# (February 12th, 2008)
- Social Networking & Dating sites (February 7th, 2008)
- Why shouldn't I use PHP short tags? (January 30th, 2008)
- Ajax (January 12th, 2008)
iEntry 10th Anniversary
Announcements










