...

View Full Version : <?php or <?



]|V|[agnus
10-05-2004, 03:55 AM
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. :cool:

mindlessLemming
10-05-2004, 05:12 AM
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:


<?xml version="1.0" encoding="utf-8" ?>
;)

]|V|[agnus
10-05-2004, 05:43 AM
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?

hemebond
10-05-2004, 05:54 AM
<? 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.

]|V|[agnus
10-05-2004, 05:59 AM
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.

hemebond
10-05-2004, 07:03 AM
Then how about a link to the page in question and a phpinfo page?

]|V|[agnus
10-05-2004, 07:09 AM
http://sethrasmussen.com/
http://sethrasmussen.com/phpinfo.php

firepages
10-05-2004, 07:26 AM
<?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 ;)

]|V|[agnus
10-05-2004, 07:29 AM
usual workaround is to echo such tags
<?echo '<'.'?xml blah';?>

Right, that's what I thought.


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.

firepages
10-05-2004, 07:49 AM
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 :D

]|V|[agnus
10-05-2004, 07:53 AM
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?"

Dylan Leblanc
10-05-2004, 03:31 PM
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

]|V|[agnus
10-05-2004, 03:35 PM
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...

ReadMe.txt
10-05-2004, 05:07 PM
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.

AaronW
10-05-2004, 05:46 PM
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.

mordred
10-05-2004, 07:08 PM
I do prefer the <?php style because it's always available, so I don't have to worry whether the server where the application will run has short_open_tags enabled or not... there already enough server-dependent configuration issues you'll have to observe.

Also most of the frameworks I work with use this style as well, so I try to be consistent to this "standard" as well.

It's convenient to use the <?= shortcut, but it never bothered me to type "<?php print $foobar; ?>". If it would, I'd either create a keyboard template in my editor, or use a template engine.

gsnedders
10-05-2004, 07:08 PM
I've use <?php for 2 reason: Compatibility
Habit

Celtboy
10-06-2004, 12:30 AM
I'm in the same camp as the last 2 posters...

I generally prefer brevity, (a la "shorthand" in CSS), but when it comes to developing any kinda coded application, I like to be as specific as I possibly can. For me, at least, it is infinitely easier. There is always the possibility that a webserver will adjust the default delimiters for other languages, as well...

What if they were changed from <% %> to <? ?> for asp? Having the "php" there is a nice identifier that just says "Hey...this is PHP code...."

also makes it easy to search for 'php' code in an embedded document :thumbsup:

-Celt

AaronW
10-06-2004, 12:51 AM
I figure if I ever to add the 'php' bit to '<?', I'll do a global find and replace on my application's directory.

But I've yet to write any kind of distributed application. Anything I write for myself or a client is hosted by myself or a host I know. So I guess it's never come up, and I'll cross that bridge when I get to it. Heh.

celestine
10-06-2004, 02:11 AM
I always use the normal tags <?php . All my codes are in <?php tags. I did that for portability and the fact that I know it'll always works.

htaccess don't work on NT and I have some clients on NT servers. It would be hard for me to get the host to set the short tags on on a shared hosting enviornment.

]|V|[agnus
10-06-2004, 07:45 AM
Some good points were raised in favor of <?php ... enough to make me reconsider my position.

I tried to take brevity to extremes with variable names for a while, but ultimately concluded that the people advocating occasionally longer but ultimately more descriptive naming conventions were on to something. ;)

This annoys me now, but I can see some benefits to adapting for the future.

I could also just change the friggin' syntax highlighting. :D

gsnedders
10-06-2004, 06:58 PM
But I've yet to write any kind of distributed application.

I'm writing one at the moment... but development has currently stopped.

circusbred
10-06-2004, 07:39 PM
Those 3 characters can save some serious headaches. At my firm, we favor the long way, plenty of white space, no short tags, and comments, oh dear lord the comments. It helps to have the code easier to read when more than one person will be working on that project.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum