SitePoint Sponsor

User Tag List

View Poll Results: Do you use the short open tag in >= PHP 5.4

Voters
9. You may not vote on this poll
  • Yes

    0 0%
  • No

    9 100.00%
Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Do you use the short open tag (<?=) in >= PHP 5.4

    Hi all,

    Prior to PHP 5.4, all PHP experts say that we should not use the short open tag (for various reasons), but since PHP 5.4, it is enabled by default again.

    So I wanted to know if you are going to keep the "good practice" and does not use or otherwise you will use in your new projects?


    I await your feedback!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,181
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Enabled or not, I've never used short tags and I see no compelling reason to start using them now. Why? To save a few keystrokes?

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Short tag is less portable and not recommended.
    Quality codes are optimized and tested...
    Click here for inspiration..

  4. #4
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    I dont, as a software developer I am creating a script used by primarily users running free/shared webhosts, cant assume most of them enable short tags.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,145
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    I don't use short tags either. I just don't see the purpose. <? versus <?php is all you are talking about....

  6. #6
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,497
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cpradio View Post
    I don't use short tags either. I just don't see the purpose. <? versus <?php is all you are talking about....
    It makes sense only in views/templates so instead of

    PHP Code:
    <div>
        <ul class="nav">
            <li><?php echo $nav_link'home' ]; ?></liv>
            <li><?php echo $nav_link'about' ]; ?></liv>
            <li><?php echo $nav_link'contact' ]; ?></liv>
        </ul>
    </div>
    you can do:

    PHP Code:
    <div>
        <ul class="nav">
            <li><?= $nav_link'home' ]; ?></liv>
            <li><?= $nav_link'about' ]; ?></liv>
            <li><?= $nav_link'contact' ]; ?></liv>
        </ul>
    </div>
    What doesn't make sense to me is that while a number of people just rave on about how short tags are evil, they have no issues using similar shorthand when provided by a template engine so they can do something like:

    Code:
    <div>
        <ul class="nav">
            <li>{{ nav_link[ 'home' ] }}</liv>
            <li>{{ nav_link[ 'about' ] }}</liv>
            <li>{{ nav_link[ 'contact' ] }}</liv>
        </ul>
    </div>
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!

  7. #7
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Myself included, everyone tries to shorten css. But css is handled client side. Php server side. I would guess server side is faster so shortening has less effect.

  8. #8
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the title you are showing short echo tags not short tags, short echo tags (new classification in 5.4) are always enabled.
    http://php.net/manual/en/language.ba...ax.phpmode.php

    "Note:

    Starting with PHP 5.4, short echo tag <?= is always recognized and valid, regardless of the short_open_tag setting."

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,822
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    I always use the short <?php ?> version of the PHP tags rather than the longer <script language="php"> </script> version.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    SitePoint Enthusiast laresistance2's Avatar
    Join Date
    May 2011
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    I always use the short <?php ?> version of the PHP tags rather than the longer <script language="php"> </script> version.
    LOL, nobody uses the <script language="php"> </script> tag!


Tags for this Thread

Bookmarks

Posting Permissions

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