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?

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

3 Comments

Interesting. Thanks for the quick response!
but remember, short tags are deprecated in PHP 6. You can enable short tags by using ini_set()
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.