Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23

Thread: <?php or <?

  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    <?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.
    Last edited by ]|V|[agnus; 10-05-2004 at 04:56 AM. Reason: Title friendly to people not familiar with the term "short tags"

  • #2
    Senior Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    1,963
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    <? 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.

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Then how about a link to the page in question and a phpinfo page?

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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)

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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)

  • #11
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?"

  • #12
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #13
    Regular Coder
    Join Date
    May 2004
    Location
    Minneapolis, MN, USA
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #14
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)

  • #15
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •