1/**
2 * This function compiles a message that tells you how great coffee is
3 *
4 * @param string $compliment A nice word to describe coffee
5 * @param integer $score A score out of 10
6 */
1
2A nice way to toggle the commenting of blocks of code can be done by mixing the two comment styles:
3<?php
4//*
5if ($foo) {
6 echo $bar;
7}
8// */
9sort($morecode);
10?>
11
12Now by taking out one / on the first line..
13
14<?php
15/*
16if ($foo) {
17 echo $bar;
18}
19// */
20sort($morecode);
21?>
22..the block is suddenly commented out.
23This works because a /* .. */ overrides //. You can even "flip" two blocks, like this:
24<?php
25//*
26if ($foo) {
27 echo $bar;
28}
29/*/
30if ($bar) {
31 echo $foo;
32}
33// */
34?>
35vs
36<?php
37/*
38if ($foo) {
39 echo $bar;
40}
41/*/
42if ($bar) {
43 echo $foo;
44}
45// */
46?>
47
48
1
2Comments do NOT take up processing power.
3
4So, for all the people who argue that comments are undesired because they take up processing power now have no reason to comment ;)
5
6<?php
7
8// Control
9echo microtime(), "<br />"; // 0.25163600 1292450508
10echo microtime(), "<br />"; // 0.25186000 1292450508
11
12// Test
13echo microtime(), "<br />"; // 0.25189700 1292450508
14# TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
15# .. Above comment repeated 18809 times ..
16echo microtime(), "<br />"; // 0.25192100 1292450508
17
18?>
19
20They 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).
21
1
2MSpreij (8-May-2005) says /* .. */ overrides //
3Anonymous (26-Jan-2006) says // overrides /* .. */
4
5Actually, 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.
6
7Thus, if a comment is opened with:
8 // then /* and */ are "overridden" until after end-of-line
9 /* then // is "overridden" until after */
10
1
2<h1>This is an <?php # echo 'simple';?> example</h1>
3<p>The header above will say 'This is an example'.</p>
4
1
2Be careful when commenting out regular expressions.
3
4E.g. the following causes a parser error.
5
6I do prefer using # as regexp delimiter anyway so it won't hurt me ;-)
7
8<?php
9
10/*
11
12 $f->setPattern('/^\d.*/');
13
14*/
15
16?>
17
18