4

In the last two days, ive run across code that has php echo'd variables displayed like this

<?=$selected?>

What exactly is going on and why? What is this called?

mrpatg
  • 10,001
  • 42
  • 110
  • 169

1 Answers1

11

That's called a Short Tag. It's a shortcut to <?php echo $selected;?>. It is widely adopted, but there's a lot of literature out there that does not recommend its use as it leads to less portable code (many PHP installations do not have short tags enabled). I happen to agree, just take a look at this user's woes. Also, see:

Are PHP Short Tags acceptable to use?

Community
  • 1
  • 1
karim79
  • 339,989
  • 67
  • 413
  • 406
  • Interesting. Thanks for the quick response! – mrpatg Nov 01 '09 at 10:16
  • 1
    but remember, short tags are deprecated in PHP 6. You can enable short tags by using ini_set() – mauris Nov 01 '09 at 11:31
  • 3
    You can't enable it with ini_set(), because the file is parsed before any ini_set() are executed, and at the time they are executed, the PHP document has been parsed already. If you want to use = and still have portable application, you can use a stream wrapper that converts short tags to long tags. This is what Zend Framework does for example (eg. include 'zend.view://file.php'), but be aware that it degrades performance. – reko_t Nov 01 '09 at 11:51