Can I use hash sign (#) for commenting in PHP?
I have never, ever, seen a PHP file using hashes ( #
) for commenting. But today I realized that I actually can! I'm assuming there's a reason why everybody uses //
instead though, so here I am.
Is there any reason, aside from personal preference, to use //
rather than #
for comments?
The answer to the question Is there any difference between using "#" and "//" for single-line comments in PHP? is no .
There is no difference. By looking at the parsing part of PHP source code, both "#" and "//" are handled by the same code and therefore have the exact same behavior.
PHP's documentation describes the different possibilities of comments. See http://www.php.net/manual/en/language.basic-syntax.comments.php
But it does not say anything about differences between "//" and "#". So there should not be a technical difference. PHP uses C syntax, so I think that is the reason why most of the programmers are using the C-style comments '//'.
<?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
?>
RTM
链接地址: http://www.djcxy.com/p/1864.html上一篇: 大括号/没有大括号?