7

I would like to know how to escape phpdoc comments within a phpdoc comment.

For example, how would I have to write this:

/**
 * Some documentation...
 *
 * <code>
 * /**
 *  * Example example phpdoc.
 *  */
 * </code>
 */

Obviously above example won't work.

I tried replacing the asterisk's with &#x2A;, but it will just nicely print "&#x2A;"...

Tader
  • 25,802
  • 5
  • 26
  • 27

2 Answers2

10

According to DocBlock Description details, you can, as of 1.2.0rc1, write {@*} to write */.

For example:

/**
 * Simple DocBlock with a code example containing a docblock
 *
 * <code>
 *  /**
 *   * My sample DocBlock in code
 *   {@*} 
 * </code>
 */
Tader
  • 25,802
  • 5
  • 26
  • 27
  • Is there a complete list of all strings that must be escaped? So far I learned that `@` must be escaped with `\@` and `*/` must be represented as `{@*}`. Is that all, or is there more? – Danon Nov 19 '22 at 19:48
0

You need to use @example. Add the following lines after the tag </code>

 @example /path/to/example.php How to use this function
 @example anotherexample.inc This example is in the "examples" subdirectory

You can find more info here. So you apparently need to have the example code in a separate file too.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697