Take the 2-minute tour ×

Even the official documentation used to tell us that PHP "short tags" (<? /*...*/ ?>) are "bad". However, since PHP 5.4, the echo variety <?= /*...*/ ?> is permanently enabled regardless of the short_open_tag setting.

What's changed?

Even if they were previously discouraged solely due to the unpredictable nature of whether short_open_tag is enabled on a shared hosting platform, surely that argument doesn't go away just because some subset of hosts will be running PHP 5.4?

Arguably this change to the language doesn't inherently signify a change in the recommendation that we should nonetheless avoid "short tags", but if they've gone to the trouble it would certainly seem like the PHP devs no longer "hate" them so much. Right?

The only logical conclusion I can draw at this time is that there must be some objective rationale for the introduction of this change in PHP 5.4.

What is it?

share|improve this question
If I read php.net/manual/en/language.basic-syntax.phpmode.php correctly, your question isn't quite correct - <?= (short-tag echo) is always enabled, but other short tag usages aren't (untested). Still, I'd be interested to know the reasoning for that change as well. –  therefromhere Jan 7 '13 at 0:45
You mean "short echo tag <?= is always recognized and valid"? That's just used for echo and they are permanently enabled, AFAIK –  Vahid Farahmand Jan 7 '13 at 0:45
That's not what it says. All it says is the <?= which is equivalent to <?php echo ...?> is always available. –  Cfreak Jan 7 '13 at 0:45
The original reasoning for introducing the config option for short tags was that some sheople had the unsuppressible urge to mix PHP into XML files, where <? clashed with <?xml. Now it was uncovered that most XML editors that people appearantly use for editing PHP files don't bail when encountering <?= or so. –  mario Jan 7 '13 at 0:46
@mario that would make sense, do you have a link to a relevant dev mailing list discussion or similar? –  therefromhere Jan 7 '13 at 0:48
show 4 more comments

4 Answers

up vote 14 down vote accepted

Short open tags are not always enabled since PHP 5.4. The documentation talks about the short echo tags. Which is a different thing. (short open tags are <? style tags, short echo tags are <?= style tags, for echo-ing).

Then why are they enabled by default now? Well, there are a lot of scripts out there, where it benefits to use <?= $somevar ?> instead of <?php echo $somevar ?>. And because the short echo tags aren't as bad as the short open tags, they chose to always enable the short echo tags. Because now developers (of frameworks and CMS-es) can count on them (or rather, when PHP 5.4 becomes mainstream).

However, the short open tags are still influenced by the short_open_tag setting in your php.ini.

share|improve this answer
I guess that makes sense. I mean, as much as any PHP design decision ever has... –  Lightness Races in Orbit Jan 7 '13 at 0:47
Well, giving the same behavior on all installations is a good thing. The more options we have the more things one has to mind. The thing here is that in templates the short echo is nice, but short open tags cause conflicts with XML processing instructions (think <?xml, <?xsl, ...) , so we added higher comfort for portable code ... I hope that explains the sense of the design decision in this case -Johannes (PHP Development Team Member) –  johannes Jan 7 '13 at 0:54
@johannes: It's not "all" installations though. By releasing a new version you by definition add a new option that not everybody will have, despite the best intentions (for example). Was this something that was raised within the dev team during the discussions leading up to the feature change? –  Lightness Races in Orbit Jan 7 '13 at 0:56
Well, we can't change the past. We can try to improve for the future, though. At least as much as legacy allows ... –  johannes Jan 7 '13 at 0:58
But maybe somebody can borrow his time machine, there are quite some things in PHP I really would love to change from the start which can't be made undone none –  johannes Jan 7 '13 at 0:58
show 4 more comments


All that this is saying, is that <?= is always valid, and not <?

share|improve this answer
Yes, but the question is why. –  Lightness Races in Orbit May 16 '13 at 11:09
add comment

Only short echo tag (<?=) is enabled permanently, not short open tags (<?). It's because short echo tag is really handy when you're creating HTML templates (or any other view templates) and without that you have to write a lot more (like <?php echo $var; ?> instead of just <?= $var ?>).

share|improve this answer
add comment

The reason is that < ? is used in XML documents and enabling short_open_tags will generate errors in XML codes. But, < ?=, just like < ?php is not XML open tag and is safe to use.

share|improve this answer
add comment

Your Answer


