用户评论:
[#1]
Haiter [2015-04-30 22:25:13]
Pairs like the code very good.
Example:
//It returns 24
[#2]
J. Prettyman [2014-02-13 05:55:53]
Notes can come in all sorts of shapes and sizes. They vary, and their uses are completely up to the person writing the code. However, I try to keep things consistent in my code that way it's easy for the next person to read. So something like this might help...
// CATEGORY LARGE FONT
//======================================================================
//-----------------------------------------------------
// Sub-Category Smaller Font
//-----------------------------------------------------
# Option 1
# Option 2
# Option 3
// This is a single line quote.?>
[#3]
magnesium dot oxide dot play+php at gmail dot com [2013-10-10 10:02:58]
It is worth mentioning that, HTML comments have no meaning in PHP parser. So,
WILL execute some_function() and echo result inside HTML comment.
[#4]
Anonymous [2013-10-09 07:02:02]
The comment priority is depended on the order:
1. */
2. ?>
3. // and #
[#5]
Clem at no dot spam [2013-04-19 14:47:10]
Uncommented:
Commented:
[#6]
team at researchbib dot com [2011-09-13 19:25:26]
when the comment string contains '?>', you should be careful.
e.g. output code 1= code 2 is different with code 3
1. with //
<?php // echo '<?php ?>';?>
2. with #
<?php // echo '<?php ?>';?>
3. with
[#7]
philip-php at dago dot yourweb dot de [2011-03-05 10:29:49]
It's true, comments do not take up PROCESSING time, but they do take some PARSING time in case you are not using a compile cache of some kind.
[#8]
jballard at natoga dot com [2010-12-15 14:28:49]
Comments do NOT take up processing power.
So, for all the people who argue that comments are undesired because they take up processing power now have no reason to comment ;)
<?php // Controlechomicrotime(),"
";// 0.25163600 1292450508echomicrotime(),"
";// 0.25186000 1292450508
// Testechomicrotime(),"
";// 0.25189700 1292450508
# TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
# .. Above comment repeated 18809 times ..echomicrotime(),"
";// 0.25192100 1292450508?>
They take up about the same amount of time (about meaning on a repeated testing, sometimes the difference between the control and the test was negative and sometimes positive).
[#9]
benny at bennyborn dot de [2010-12-08 03:16:06]
This regex should do the job when trying to parse comments
(\/\*(.*?)\*\/)|(^|\s+)\/\/(.*?)(\n|$)|(^|\s+)#(.*?)(\n|$)
[#10]
Wolfsbay at ya dot ru [2010-05-12 14:10:37]
If you are using editor with code highlight, it??s much easier to notice error like */.
[#11]
theblazingangel at aol dot com [2007-08-28 15:55:59]
it's perhaps not obvious to some, but the following code will cause a parse error! the ?> in //?> is not treated as commented text, this is a result of having to handle code on one line such as <?phpecho 'something';//comment ?><?phpif (1==1)
{//?>}?>
i discovered this "anomally" when i commented out a line of code containing a regex which itself contained ?>, with the // style comment.
e.g. //preg_match('/^(?>c|b)at$/', 'cat', $matches);
will cause an error while commented! using style comments provides a solution. i don't know about # style comments, i don't ever personally use them.
[#12]
fun at nybbles dot com [2006-07-13 22:28:39]
a trick I have used in all languages to temporarily block out large sections (usually for test/debug/new-feature purposes), is to set (or define) a var at the top, and use that to conditionally comment the blocks; an added benefit over if(0) (samuli's comment from nov'05) is that u can have several versions or tests running at once, and u dont require cleanup later if u want to keep the blocks in: just reset the var.
personally, I use this more to conditionally include code for new feature testing, than to block it out,,,, but hey, to each their own :)
this is also the only safe way I know of to easily nest comments in any language, and great for multi-file use, if the conditional variables are placed in an include :)
for example, placed at top of file:
and then deeper inside the file:
print("This code is included since we are testing version 3");
}?>
print("This code is 'commented' out");
}?>
[#13]
mst_NO_SPAM_TO_ME at mstsoft dot com [2006-06-05 05:38:23]
This "comment ends on line break or end of PHP Block" thing can be confusing. I discovered this by accident when working with XML Output from PHP...
header("Content-type: text/xml");//echo "<?phpxml version=\"1.0\"?>";
//echo "single-line comments end php mode and output your code.";
?>
I would expect the comment to work, but there is no parsing in comments so the String suddenly becomes a PHP end-block tag, which is correct reading this documentation.
cheers,
martin
PS: You even see the behavior in the Syntax highlighting :-)
[#14]
J Lee [2006-05-25 23:39:53]
MSpreij (8-May-2005) says overrides //
Anonymous (26-Jan-2006) says // overrides
Actually, both are correct. Once a comment is opened, *everything* is ignored until the end of the comment (or the end of the php block) is reached.
Thus, if a comment is opened with:
// then are "overridden" until after end-of-line
[#15]
[2006-01-21 01:46:21]
M Spreij wrote, 08-May-2005 08:15...
A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
...
This works because a overrides //.
The final sentence should be the other way round, i.e.
This works because a // overrides .
(If it didn't the would comment out the code regardless of whether an additional '/' is prefixed to the first line).
[#16]
samuli dot karevaara at lamk dot fi [2005-11-11 08:30:47]
If you want to comment out large sections of code (temporarily, usually and hopefully), consider using
print("This code is 'commented' out");
}?>
instead of . Otherwise, as noted here, you will have parse errors if the block that you commented out contains */ somewhere, like in regexp or in another comment.
[#17]
hcderaad at wanadoo dot nl [2005-06-29 13:51:51]
Comments in PHP can be used for several purposes, a very interesting one being that you can generate API documentation directly from them by using PHPDocumentor (http://www.phpdoc.org/).
Therefor one has to use a JavaDoc-like comment syntax (conforms to the DocBook DTD), example:
Some basic html-like formatting is supported with this (ie
tags) to create something of a layout.
[#18]
M Spreij [2005-05-08 12:15:37]
A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
Now by taking out one / on the first line..
..the block is suddenly commented out.
This works because a overrides //. You can even "flip" two blocks, like this:
if ($bar) {
echo $foo;
}
// */?>
vs
echo$foo;
}// */?>
[#19]
Steve [2004-12-15 04:41:38]
Be careful when commenting out regular expressions.
E.g. the following causes a parser error.
I do prefer using # as regexp delimiter anyway so it won't hurt me ;-)
*/
?>