Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-05-2004, 03:55 AM   PM User | #1
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
<?php or <?

Just curious what people's preferences are. Personally, I can't understand why you'd prefer to open every block of PHP with <?php as opposed to <? other than it maybe being more understandable for beginners... maybe being more obtuse helps? At the same time, how hard is it to get used to <? ... I mean, it actually matches the end tag then, which is common to every other usage of tags in other languages.

Maybe I'm biased by syntax highlighting. <?php and ?> are rendered in a bold red in Dreamweaver, so <?php all over the screen is frankly just distracting, too!

Anyway... your thoughts on this oh so important topic, please.
__________________

Opposite of Sequitur

Last edited by ]|V|[agnus; 10-05-2004 at 03:56 AM.. Reason: Title friendly to people not familiar with the term "short tags"
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 05:12 AM   PM User | #2
mindlessLemming
Senior Coder

 
Join Date: Oct 2003
Location: Australia
Posts: 1,963
Thanks: 0
Thanked 0 Times in 0 Posts
mindlessLemming is an unknown quantity at this point
Two words that will explain why short tags are now turned off by default.
xml prologue
Ever seen a full page of nothing from a faultless xhtml+php page?

**for anyone who doesn't know what an xml prologue looks like:
Code:
<?xml version="1.0" encoding="utf-8" ?>
__________________

I take no responsibility for the above nonsense.


Left Justified
mindlessLemming is offline   Reply With Quote
Old 10-05-2004, 05:43 AM   PM User | #3
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
This occurred to me, but after giving it some thought, I wondered how there would be a problem. An XML parser should never seen any <? ?> PHP tags, correct? And the PHP parser should only start parsing if it encounters <? or <?php followed by a space, yes?

Or should I give you the benefit of the doubt and assume no, and rather ask for how my reasoning is flawed?
__________________

Opposite of Sequitur
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 05:54 AM   PM User | #4
hemebond
Senior Coder

 
Join Date: Jul 2004
Location: New Zealand
Posts: 1,315
Thanks: 0
Thanked 2 Times in 2 Posts
hemebond is an unknown quantity at this point
<? will work when short-tags is turned on.
<?php will work regardless of whether short-tags are turned on or not.
<?xml will be parsed by the PHP parser if short-tags are turned on.
hemebond is offline   Reply With Quote
Old 10-05-2004, 05:59 AM   PM User | #5
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
The last line there is the one we want...

So then the spaces are not required after or before the PHP tags? In Dreamweaver, <?$var=1;?> would not be highlighted as PHP nless the spaces are present. Perhaps syntax highlighting has biased me yet again?

P.S. I've got plenty of short tags in my site, and when viewed through Firefox, for example, it is served as XML, and I've had no issues related to short tags.
__________________

Opposite of Sequitur
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 07:03 AM   PM User | #6
hemebond
Senior Coder

 
Join Date: Jul 2004
Location: New Zealand
Posts: 1,315
Thanks: 0
Thanked 2 Times in 2 Posts
hemebond is an unknown quantity at this point
Then how about a link to the page in question and a phpinfo page?
hemebond is offline   Reply With Quote
Old 10-05-2004, 07:09 AM   PM User | #7
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
http://sethrasmussen.com/
http://sethrasmussen.com/phpinfo.php
__________________

Opposite of Sequitur
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 07:26 AM   PM User | #8
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,891
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
Quote:
Originally Posted by hemebond
<?xml will be parsed by the PHP parser if short-tags are turned on.
usual workaround is to echo such tags
<?echo '<'.'?xml blah';?>

short tags are recommended for re-distributable applications for the reasons noted above.

To be honest this irks me
I personally have yet to meet a server with short tags turned off that I did not have control of anyway (e.g. shared servers),
Turning short tags off also restricts some nice shortcuts <?=$echo_this;?>
Its less typing.

in an average php document , how many XML tags ? how many PHP tags ? EOF
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 10-05-2004, 07:29 AM   PM User | #9
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
Quote:
Originally Posted by firepages
usual workaround is to echo such tags
<?echo '<'.'?xml blah';?>
Right, that's what I thought.

Quote:
Originally Posted by firepages
short tags are recommended for re-distributable applications for the reasons noted above.

To be honest this irks me
I personally have yet to meet a server with short tags turned off that I did not have control of anyway (e.g. shared servers),
Turning short tags off also restricts some nice shortcuts <?=$echo_this;?>
Its less typing.

in an average php document , how many XML tags ? how many PHP tags ? EOF
I'm a little confused... you sounded irked by the recommendation that short tags be used, yet proceeded to defend and promote them? I think I misinterpreted something, but I sit confused.
__________________

Opposite of Sequitur
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 07:49 AM   PM User | #10
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,891
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
DOH , typo , short tags are not recommended & it is this that irks me.... that's what I meant even if thats not what I said
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 10-05-2004, 07:53 AM   PM User | #11
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
Heheh, okay. And under that pretense, the full <?php ?> tags make more sense, I guess.

What server administrator would be unwilling to turn on something like that anyway? I mean, did <?php ever have any functional significance over <? or did the short tags just come about when somebody said, "So uh... do I really need to keep typing "php" over and over?"
__________________

Opposite of Sequitur
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 03:31 PM   PM User | #12
Dylan Leblanc
Regular Coder

 
Join Date: Sep 2002
Location: British Columbia
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Dylan Leblanc is an unknown quantity at this point
I use short tags because I don't do anything with XML and I find it easier to output code with the <?= syntax, which is much easier than typing <?php echo
__________________
http://skyscraperpage.com/
Dylan Leblanc is offline   Reply With Quote
Old 10-05-2004, 03:35 PM   PM User | #13
]|V|[agnus
Regular Coder

 
Join Date: May 2004
Location: Minneapolis, MN, USA
Posts: 904
Thanks: 0
Thanked 0 Times in 0 Posts
]|V|[agnus is an unknown quantity at this point
I really like this <?= syntax you guys are talking about. I wasn't aware of this, and had actually been wanting something effectively like that for a while now. Sweeeeet...
__________________

Opposite of Sequitur
]|V|[agnus is offline   Reply With Quote
Old 10-05-2004, 05:07 PM   PM User | #14
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
personally i prefer short tags, for the same reason that firepages does.

As an aside you can use the .htacess php_flag syntax to enable or disable it to your liking:

php_flag short_open_tag 0

or 1 if you want them on.
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 10-05-2004, 05:46 PM   PM User | #15
AaronW
Senior Coder

 
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 1,223
Thanks: 0
Thanked 0 Times in 0 Posts
AaronW is an unknown quantity at this point
Short tags here, too. Just seems pointless to type the language over and over... Imagine!

<%asp
<html ... Ok this one's real, but we don't have to do <html p>, thank God!
<!--COMMENT

Hehe. Saves me typing.

Oh, and using the short echo syntax, you don't even need a semicolon!

<?="Moo!"?>

Works splendidly.
__________________
offtone.com | offtonedesign.com
AaronW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:04 AM.


Advertisement
Log in to turn off these ads.