PHP Short tag question

Discussion in 'PHP' started by bertamus11, Apr 3, 2013.

  1. #1
    Hi there, my host won't turn on short tags and I have a script that has some in it so it won't work. My question is what do I change this to?: <?= Do I just use <?php or is it <?php echo, or?

    Thanks for your help!
     
    Solved! View solution.
    bertamus11, Apr 3, 2013 IP
  2. #2
    "<?php echo" is right choise.
     
    IGarret, Apr 3, 2013 IP
  3. bertamus11

    bertamus11 Well-Known Member

    Messages:
    791
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Awesome. Thank you IGarret!
     
    bertamus11, Apr 3, 2013 IP
  4. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #4
    HuggyStudios, Apr 3, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Good lord why the **** would they do that? (NOT A FAN of the needlessly cryptic)

    Can you find proof of that on a php.net since I'm not finding it.... Oh wait, I see it... Ok, that's KIND-OF true.

    In PHP 5.4 <?= is always available, but <? still obeys shorttags being off... Lemme test...

    Yup, that's how it works. Though again, if I had by way all of those would be stricken from PHP entirely.
     
    deathshadow, Apr 4, 2013 IP
  6. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #6
    Because humans are lazy, that's why.


    That sounds pretty stupid to me.
     
    GMF, Apr 4, 2013 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    There's a reason for it, and it's also why the use of shorttags is discouraged and disabled by default. <? conflicts with outputting XML. (though I get around that by never outputting code anyplace but with ECHO, since you can <?php ?> inside a string all you want and it won't trip!)

    With shorttags on, this:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
    	<to>Dumbass</to>
    	<from>Red</from>
    	<heading>Reminder</heading>
    	<body>Don't be a dumbass</body>
    </note>
    Code (markup):
    In a .php file would fail to output the XML header, and instead try to parse that XML declaration as PHP! That's why shorttags is off by default. Apparently <?= doesn't trip this bug (for obvious reasons, that one extra character). A doctype can cause similar issues.

    To get around this problem, you either need to turn off shorttags, or echo it out.

    Even with shorttags on, even in older versions of PHP, this would never have that problem:
    <?php
    echo '<?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
    	<to>Dumbass</to>
    	<from>Red</from>
    	<heading>Reminder</heading>
    	<body>Don't be a dumbass</body>
    </note>';
    Code (markup):
    But again that's another reason I'm in favor of <?php and ?> being stricken from the language entirely. Either that or have a new file extension as a trigger to say "ALL of this is PHP, ignore PHP start/end tags"
     
    deathshadow, Apr 4, 2013 IP
    GMF likes this.