注释掉使用速记符号回显的PHP变量的正确方法是什么? [英] What is the correct way to comment out a PHP variable being echoed using shorthand notation?

查看:60
本文介绍了注释掉使用速记符号回显的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.

这篇关于注释掉使用速记符号回显的PHP变量的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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