我能够注释掉已经被注释的行吗?
/*
* comment 1
*/
$var = 0;
$if();
/*
* comment 2
*/
$var2 = 2;
有没有一种方法可以将所有这些行一起注释掉? 我经常有一个很长的函数或逻辑,并希望在测试时注释掉其余部分。
您是否考虑过通过将代码放置在if(0)块中来跳过代码?
例如:
<?php
if( 0 ) {
print("This code is 'commented' out");
... other commented out code is here ...
}
?>
if ($debug)
或if (! $debug)
。 - HeatfanJohn来自 PHP 手册:
'C' style comments end at the first */ encountered. Make sure you don't nest 'C' style comments. It is easy to make this mistake if you are trying to comment out a large block of code.
<?php /* echo 'This is a test'; /* This comment will cause a problem */ */ ?>
你可以尝试使用Heredoc语法,例如:
<<<VAR
/*
* comment 1
*/
$var = 0;
$if();
/*
* comment 2
*/
$var2 = 2;
VAR;
<<<'VAR'
。 - ThiefMaster/* */
,并使用更多的行注释//
或#
。大多数代码编辑器都允许您使用//
来注释和取消注释整个代码块。通常是一些组合键,例如Ctrl+Shift/Alt+C
。非常方便,请查看您的文本编辑器的参考资料。
#
、//
)时,才能实现这个功能。 - Yoshi