Source Code Fundamentals: Comments

There are two forms of comments: delimited and single-line. For example:

/* Class Point represents a point in a two-dimensional Cartesian
coordinate system. */

class Point {
  private float $x; // x-coordinate
  private float $y; #  y-coordinate
  public function __construct(num $x = 0, num $y = 0) {
    $this->x = (float)$x; // initialize private field $x
    $this->y = (float)$y; /* initialize private field $y */
  }
  // ...
}

A delimited comment starts with /* and ends with */, and may span source lines. It may contain any characters except the sequence */. A delimited comment may occur in any place in a script in which white space may occur. For example:

/*...*/$c/*...*/=/*...*/567/*...*/;/*...*/

is interpreted as

$c=567;

and

$k = $i+++/*...*/++$j;

is interpreted as

$k = $i+++ ++$j;

A single-line comment starts with // or #, and ends with a new line, which is not part of the comment.

A number of special comments are recognized; they are:

  • // FALLTHROUGH
  • // strict
  • /* HH_IGNORE_ERROR[nnn] */, where nnn is the compiler error number that is to be ignored.