除了懒惰之外,还有一个很好的理由不使用
发布于 2024-12-11 22:41:25 字数 513 浏览 5 评论 0 原文

可能的重复:
PHP 开放标签之间有什么区别“

而不是输入:

<?php echo $foo; ?>

我已经看到它写了

<?= $foo; ?>

但我经常想知道这样做的风险/不切实际是什么?只是好奇。谢谢!

Possible Duplicate:
What is the difference between the PHP open tags “<?=” and “<?php”/“<?”?

Rather than type:

<?php echo $foo; ?>

I have seen it written

<?= $foo; ?>

But I've often wondered what the risk/impracticalities are of doing it? Just curious. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

逆流 2024-12-18 22:41:25

如果您碰巧将代码移至未启用 short_open_tag 的环境,您将暴露大量内部变量名称(安全问题)并产生大量损坏的输出。

另一个缺点是,允许使用 的设置与允许您仅使用 打开 PHP 标签的设置相同,因此禁用它会不仅公开您尝试显示的那些特定变量,还显示短标签内的任何 PHP 代码。

If you happen to move the code to an environment where short_open_tag isn't enabled, you'll be exposing a lot of internal variable names (security issue) and have a whole lot of damaged output.

The other downside is that the same setting that allows usage of <?= is the same that lets you open PHP tags with just <?, so having it disabled would not only expose those specific variables you were attempting to display, but also display any PHP code within short tags.

﹎☆浅夏丿初晴 2024-12-18 22:41:25

第二个选项增加了可读性。第一个确保到其他系统的可移植性。

除此之外,根本没有什么区别……

The second option increases the readability. The first ensures portability to other systems.

Other than that, there is no difference at all...

薄暮涼年 2024-12-18 22:41:25

它不便携。有一个 5.4 之前的配置设置可以将其关闭,因此,如果您将脚本移动到禁用它的站点,它就会中断。

另外,在我看来,它不太明确。 很容易被忽略,但很重要

It's not portable. There's a pre-5.4 configuration setting to turn it off, so if you move your script to a site where it is disabled, it would break

Also, it's less explicit in my opinion. The difference between <?= func() ?> and <? func(); ?> is easy to miss, but important

鹿港巷口少年归 2024-12-18 22:41:25

如果在运行 PHP 时启用了短标记,则只能使用 。不使用它的实际原因是它与 xml 声明不兼容。如果您尝试使用 php 扩展输出 xml 并且启用了短标签,则必须执行类似 <? 的操作。我想您可以只回显一个字符串。

You can only use <? and <?= if short tags are enabled when you are running PHP. The actual reason not to use it is because it's incompatible with an xml declaration. If you are trying to output xml with a php extension and you have short tags enabled, you have to do something like <<??>? .. I suppose you can just echo a string.

无言温柔 2024-12-18 22:41:25

我不明白所有关于可移植性的言论。

始终存在可移植性问题。
不可能有 apache - 所以,不要使用 mod_rewrite。
不能有 PDO - 所以,不要使用准备好的语句。
不可能有 mysql - 所以,不要使用复杂的查询。
不可能有 PHP - 所以,纯 HTML 是最兼容的格式,因为可移植性问题,永远不要使用其他任何格式!

I don't understand all that portability talk.

There is ALWAYS a portability issue.
There can be no apache - so, don't use mod_rewrite.
There can be no PDO - so, don't use prepared statements.
There can be no mysql - so, don't use complex queries.
There can be no PHP - so, plain HTML is most compatible format, never use anything else because of portability issues!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文