Created
December 11, 2017 18:02
Star
You must be signed in to star a gist
PHP Comment Tips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Php supports 'C', 'C++' and Unix shell-style (Perl style) comments. For example: | |
<?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 | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//====================================================================== | |
// CATEGORY LARGE FONT | |
//====================================================================== | |
//----------------------------------------------------- | |
// Sub-Category Smaller Font | |
//----------------------------------------------------- | |
/* Title Here Notice the First Letters are Capitalized */ | |
# Option 1 | |
# Option 2 | |
# Option 3 | |
/* | |
* This is a detailed explanation | |
* of something that should require | |
* several paragraphs of information. | |
*/ | |
// This is a single line quote. | |
?> | |
<?php | |
<!------------------------Text1----------------------START--> | |
echo "Some text goes here"; | |
<!------------------------Text1----------------------END--> | |
<!------------------------Text2----------------------START--> | |
echo "Some text goes here"; | |
<!------------------------Text2----------------------END--> | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
// Control | |
echo microtime(), "<br />"; // 0.25163600 1292450508 | |
echo microtime(), "<br />"; // 0.25186000 1292450508 | |
// Test | |
echo microtime(), "<br />"; // 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 .. | |
echo microtime(), "<br />"; // 0.25192100 1292450508 | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | |
*/ | |
?> | |
Be careful when commenting out regular expressions. | |
E.g. the following causes a parser error. | |
<?php | |
/* | |
$f->setPattern('/^\d.*/'); | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment