Skip to content

Instantly share code, notes, and snippets.

@ta-riq
Created December 11, 2017 18:02
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ta-riq/3806a018805b13a68dea78ac6aeeb0dc to your computer and use it in GitHub Desktop.
PHP Comment Tips
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
?>
<?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-->
?>
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
?>
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