Why are “echo” short tags permanently enabled as of PHP 5.4?

筅森魡賤 提交于 2019-11-26 17:49:19
kokx

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.

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 ?>).

Glavić

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

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

user2983350

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!