“Commentaire en php” Réponses codées

commentaire PHP

1. /* Comment */
2. //Comment
3. #comment
Shadow

PHP Commentaires de fonction appropriés

/**
 * This function compiles a message that tells you how great coffee is
 *
 * @param string  $compliment A nice word to describe coffee 
 * @param integer $score      A score out of 10
 */
SmokeFrog

Commentaire en php


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 <?php echo 'something'; //comment ?>

<?php
if(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.
Dev

Commentaire en php


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:
<?php
/**
* The second * here opens the DocBook commentblock, which could later on<br>
* in your development cycle save you a lot of time by preventing you having to rewrite<br>
* major documentation parts to generate some usable form of documentation.
*/
?>
Some basic html-like formatting is supported with this (ie <br> tags) to create something of a layout.
Dev

Commentaire en php


<h1>This is an <?php # echo 'simple';?> example</h1>
<p>The header above will say 'This is an  example'.</p>
Dev

Commentaire en php


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 /* and */ are "overridden" until after end-of-line 
   /*  then // is "overridden" until after */
Dev

Réponses similaires à “Commentaire en php”

Questions similaires à “Commentaire en php”

Plus de réponses similaires à “Commentaire en php” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code