注释掉使用速记符号回显的PHP变量的正确方法是什么?
我最近开始使用PHP速记<?=?>
标记来回显PHP脚本中的变量等.但是我发现是否要注释掉变量,例如<?=//$ myVariable;?>
我遇到语法错误.
I have recently started using the PHP shorthand <?= ?>
tags to echo variables etc in my PHP scripts. However I find if I want to then comment out the variable, e.g. <?= //$myVariable; ?>
i get a syntax error.
这样做是否安全:<?//= $ myVariable ;??>
非常感谢!
短标签
<?= ... ?>
被翻译成
<?php echo ...; ?>
因此,要注释掉它,您必须在始终显示为空的 ...
中添加一些内容.这是我能想到的最短的方法:
So to comment it out, you have to put something into ...
that always shows up as empty. Here's the shortest I can come up with:
<?= false && ... ?>
之所以可行,是因为 echo false
不会产生任何回声.
This works because echo false
echoes nothing.
没有文档支持它,因此它可能是一个古老的兼容性黑客,但是以下方法似乎可以工作:
There's no documentation supporting it, so it might be an old compatibility hack, but the following seem to work:
<?//= ... ?>
和
<?/*= ... */?>
由于它们没有记录,因此我不会依赖它们做任何重要的事情,但是如果您只是在调试时暂时注释掉某些内容,则可以使用它们.
Since they're undocumented, I wouldn't depend on them for anything important, but you could use them if you're just temporarily commenting something out while debugging.