为什么“回声”短标签从PHP 5.4永久启用? [英] Why are "echo" short tags permanently enabled as of PHP 5.4?

查看:215
本文介绍了为什么“回声”短标签从PHP 5.4永久启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使官方文档也用来告诉我们 PHP短标签( < ;? /*...*/?> )是不良。但是,从PHP 5.4开始, echo 品种<?= /*...*/?> 永久启用,而不管 short_open_tag a>。



有什么变化?



即使他们以前不鼓励由于在共享托管平台上是否启用 short_open_tag 的不可预测性,肯定该参数不会因为某些子集的主机将运行PHP 5.4而消失? / p>

可以说,对语言的这种改变并不固有地意味着改变建议,我们应该避免短标签,但如果他们遇到麻烦肯定会像PHP开发者不再憎恨他们那么多。是吗?



我现在可以得出的唯一逻辑结论是,在PHP 5.4中引入这种变化必须有一些客观的理由。


解决方案



自PHP 5.4起,

短开标记并不总是启用。该文档介绍了短回声标签。这是一个不同的东西。 (短开标签是<?样式标签,短回显标签是<?= -ing)。



那么为什么他们默认启用呢?好吧,有很多脚本在那里,它有利于使用<?= $ somevar?> 而不是<?php echo $ somevar?> 。和因为短回声标签不如短暂打开标签那么糟,他们选择始终启用短回声标签 。因为现在开发者(框架和CMS-es)可以信赖他们(或者当PHP 5.4成为主流时)。



/ strong>标签仍受您的php.ini中的 short_open_tag 设置的影响。


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?

解决方案

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.

这篇关于为什么“回声”短标签从PHP 5.4永久启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆