the short hand php opening tag '<?' !!!

Discussion in 'PHP' started by lauthiamkok, Apr 1, 2009.

  1. #1
    Very often, when I am passed on a php-based project from another developers, I come across <? as an alternative short version of the php opening tag and it never works on my local server.

    I wonder why these programming background php developers tend to do this instead of typing a full tag. I am a designer background php developer.

    Also, I come across this very often which puzzles me,
    <?= bloginfo('template_directory'); ?>

    Is anyone can advise me how to make this short hand tag <? and <?= to work on my local server? Or please advice what I can do about them? should I change these two type of short hand to <?php ;?> ?

    Many thanks,
    Lau
     
    lauthiamkok, Apr 1, 2009 IP
  2. assault14

    assault14 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    not all servers could understand it..

    just change it too

    <?php
    ?>
     
    assault14, Apr 1, 2009 IP
  3. MaxMoskol

    MaxMoskol Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I believe I've read that <? was never meant to be permanent. Just use <?php
     
    MaxMoskol, Apr 1, 2009 IP
  4. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #4
    short_open_tag = Off
    Code (markup):
    Search that on your php.ini file and change it to On to activate short tags

    Or you can fix it, replace
    1) "<?=" with "<?php echo "
    2) "<?" with "<?php"
    3) and finally "<?phpphp" with "<?php"

    but if you have a lot of files will take you some time
     
    emed, Apr 1, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Use 'find' and 'sed' and it will take you no time at all.
     
    SmallPotatoes, Apr 1, 2009 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    DO NOT use shorthand. It is deprecated now.
     
    NatalicWolf, Apr 1, 2009 IP
  7. kusal

    kusal Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, As rule don't use the short hand, always go for <?php ?>
     
    kusal, Apr 1, 2009 IP
  8. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I hadn't heard this. Do you have any citation? I can't find it mentioned on the php.net site. If it's true then I need to make some policy changes.
     
    SmallPotatoes, Apr 1, 2009 IP
  9. arunn

    arunn Active Member

    Messages:
    347
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #9
    its nt recommended to use shortcode.. always use <?php
     
    arunn, Apr 1, 2009 IP
  10. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Shoot. I was off. I was thinking of Register Globals, which have been taken out in PHP 6. It's just not proper coding to use shorthand, unless the server supports it. I hope I didn't confuse anyone.
     
    NatalicWolf, Apr 1, 2009 IP
  11. m.stevens

    m.stevens Peon

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    There is no problem with using it. Just make sure that your server's php installation supports it and that it is enabled. If you ever need to switch to a server that doesn't support it, it will take you a few minutes to replace all the short tags.
     
    m.stevens, Apr 2, 2009 IP