我从来没有见过使用散列(#
)进行注释的PHP文件。但今天我意识到我真的能做到!我假设每个人都使用//
是有原因的,所以我在这里
除了个人偏好之外,是否还有使用//
#
而不是#
进行评论的原因?
发布于 2012-02-01 17:53:36
PHP2021更新:从 8开始,这两个字符不相同。序列#[
是used for Attributes。(感谢i336的评论)
原始答案:
这个问题的答案是,在中使用"#“和"//”表示单行注释有什么不同吗??is no.
这是没有区别的。通过查看PHP源代码的解析部分,both "#" and "//" are handled by the same code和因此具有完全相同的行为。
发布于 2012-02-01 17:52:20
PHP的文档描述了注释的不同可能性。请参阅http://www.php.net/manual/en/language.basic-syntax.comments.php
但是它没有提到"//“和"#”之间的任何区别。所以不应该有技术上的差异。PHP使用C语法,所以我认为这就是为什么大多数程序员使用C风格的注释'//‘的原因。
发布于 2012-02-01 17:50:31
<?php
echo 'This is a test'; // This is a one-line C++ style comment
/* This is a multi-line comment.
Yet another line of comment. */
echo 'This is yet another test.';
echo 'One Final Test'; # This is a one-line shell-style comment
?>
https://stackoverflow.com/questions/9093609
复制相似问题