comment in php

Solutions on MaxInterview for comment in php by the best coders in the world

showing results for - "comment in php"
Corentin
29 Jan 2018
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
Christian
26 Feb 2019
1
2<?php
3    echo 'This is a test'// This is a one-line c++ style comment
4    /* This is a multi line comment
5       yet another line of comment */
6    echo 'This is yet another test';
7    echo 'One Final Test'# This is a one-line shell-style comment
8?>
9
10
Christian
01 Aug 2018
1
2<h1>This is an <?php # echo 'simple';?> example</h1>
3<p>The header above will say 'This is an  example'.</p>
4
Eve
19 Jun 2016
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
Jonah
06 Mar 2017
1
2Comments 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/).
3
4Therefor one has to use a JavaDoc-like comment syntax (conforms to the DocBook DTD), example:
5<?php
6/**
7* The second * here opens the DocBook commentblock, which could later on<br>
8* in your development cycle save you a lot of time by preventing you having to rewrite<br>
9* major documentation parts to generate some usable form of documentation.
10*/
11?>
12Some basic html-like formatting is supported with this (ie <br> tags) to create something of a layout.
13
Leo
12 Jan 2021
1// This is a single-line comment
2 # This is also a single-line comment
Theo
24 Jun 2016
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
Rose
25 Sep 2020
1
2Notes 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...
3
4<?php
5
6//======================================================================
7// CATEGORY LARGE FONT
8//======================================================================
9
10//-----------------------------------------------------
11// Sub-Category Smaller Font
12//-----------------------------------------------------
13
14/* Title Here Notice the First Letters are Capitalized */
15
16# Option 1
17# Option 2
18# Option 3
19
20/*
21 * This is a detailed explanation
22 * of something that should require
23 * several paragraphs of information.
24 */
25 
26// This is a single line quote.
27?>
28
29
Eleonora
16 Oct 2016
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
Juan Pablo
19 Nov 2019
1
2it'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 <?php echo 'something'; //comment ?>
3
4<?php
5if(1==1)
6{
7    //?>
8}
9?>
10
11i discovered this "anomally" when i commented out a line of code containing a regex which itself contained ?>, with the // style comment.
12e.g. //preg_match('/^(?>c|b)at$/', 'cat', $matches);
13will 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.
14
queries leading to this page
how to comment on phphow to make comments in php codedocumentation comment in phpmulti line comment in phpcomment on phpadd comment on php inimultiline php commentcomment phphow to comment php in htmlphp comment linephp code commentnew line on php comment documentationcomments inn php 23 as comment in phpphp 09 line commentcomment with php codephp file commentdisplay some of the comments in phpnew line php commenthow should we add a single line comment in our php codecomment in php filehow to comments pn php tagsline comment in phpmultiline comment in phphow to add a to do comment in phpmultiline comment php classhow to add comments in a php codephp how to add comentsphp document commentphp comphp comment tagscomment html in phpwhich of the following is correct to add a comment in php 3fphp doc commentcomment code phpcomment out php codehow to add note in php codehow to comment out phpphp comment sectionwhich is the correct way to start a single line php comment 3fcomment out php in htmlcomment v phpcomment of comment phpwhat comment style to use with phpphp see commentdefine 28 29 php doc commentphp multiple linecommentcommentout in phphow to comment php codehow to coment in phpnotes in phpshortcut of comment in phpcomment in html phpphp comment single linehow to comment command in phpphp comments systemmulti line comment phpcomment php blockcomments phpphp code commentsfunction comment phpcomment out php blockcommenting phpdisplay on comment the value in phphow to comment 24 in phphow to make my line of code in php comment 40file php doc commentphp comment multiple linesputting php in commentsphp comment whole line codecomment php outcomment fonction 3c 3d 3e phpphp block remarkphp functions commentsphp comcomment for php codesphp code showing ways of commenting in phpphp document comment tagcomment in phpphp commntscomment out phpcomment php inside htmladd as comment phphow to comment out php ini linesphp get commentcomment out in phpphp large comment blockwhat is a correct way to add a comment in php 3f a 2a 5c 5c 2a b 2f 2a 2a 2f c 3c 21 3eapply comment phpcomment php codecomment out js in php filecomment phphhow to comment in phpcode comment phpdoes php code works if block comment is usedwhich of the following is the way to create comments in php 3fphp documentation commentcomments on phphow to comment a code in phpcomment code in phpcomment system phpphp comment blockhow to comment a line in phphow to add multiple line comment in phpinline comment in phpphp multiline commentmultiple line comment in phphow to comment out php codephp comment syntaxcomments in php codehow to comment multiple lines in phphow to comment phpcommenting php codehow should we add a single line comment in our php code 3fcom phpphp commentsphp commentarcomment out line phpcreating comment in phpat comments phpsingle line comment in phpcomment section phpphp 23 commentphp block commentphp ini commenthow do you make comments statements in php 3f 2aphp cpmmentcommment in phpcan 27t comment in phpphp comment functionphp comment in htmlphp comline comment phpphp comment text boxcomment a code php comment html phpwhat is a correct way to add a comment in php 3fcomment php and html codeinurl 3acomment phpcommenting in phpcommment phpcomments in phpcomment whole line phpphp ini commentsphp commentidentify the comment clause to include along with in php codehow to block a section og php codephp comment 3c 3fphp commentwsadd comments plugin for phpcomment in php vodephp multiline commentingpost comment in phphow to comment php tagcomment php in htmlcommenting out phpcomment ina phpphp comentsphp comment 40php comment outhpow tpo comment in phphow to comment out php in phtmlcomment in phpform comment phpphpcs commenthow to make a comment phphow to comments in phpcomment php and htmlcomentar en phpphp commentingphp how to comment out blockcomenting in phpphp comment out whole codecomment end phpphp comment out multiple lineshow to comment out in phpphp comment systemcoments in phpcomment everythig phphow to put comment in phpall php doc commentcoment phphow to write comment in phpblock comment phpphp green comment multiple linescommenting in php languagecomment text show in phpdisplay data in php on the commentshow to comment out a php tagcode comments out phpphp best way to comment funnctionphp create commentcomment line in phpcorrect way to comment code phpcomment in php