Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put blocks of PHP code into a PHPDoc DocBlock

I'm playing around with PHPDoc and have realised that you can use markdown to add some formatting to a DocBlock. In particular, I notice that you can use back ticks to highlight inline code.

However, I can't seem to figure out how to add blocks of code to a DocBlock, as using 4 spaces doesn't seem to work.

I've tried using <code> and <pre> too, and whilst those tags do appear in the generated documentation, the code inside them becomes commented out with HTML comments.

For example, this DocBlock:

/**  * This is a test DocBlock  *  * <pre>  *     <?php  *         echo('hi');  *     ?>  * </pre>  *  * @return object[] An array of objects.  */ 

Generates this HTML:

<pre>     <!--?php echo('hi'); ?--> </pre> 

Where am I going wrong? How can I add a block of code to my DocBlock?

like image 253
Mark Locker Avatar asked Jul 31 '12 13:07

Mark Locker


People also ask

What is a DocBlock in PHP?

A DocBlock is a piece of documentation in your source code that informs you what the function of a certain class, method or other Structural Element is.

What are phpDoc comments?

phpDoc blocks are descriptive comments that are part of the application code. They are used to describe the PHP element in the exact location in the code where the element appears. The block consists of a short description, long description, and phpDoc tags.

Why must you use phpDoc syntax to document code?

PhpDoc, short for PhpDocumentor, is a powerful tool that allows you to easily document your code via specially formatted comments. The documentation will be available not only in the source code, but also in professional documentation extracted using either the web or command-line interface.

Which of the following elements can be documented by a PhpDocumentor?

phpDocumentor is capable of automatically documenting include statements, define statements, functions, procedural pages, classes, class variables, and class methods.


1 Answers

phpdocumentor uses the github variant of markdown.

The proper way to add code, is then:

/**  * This is a test DocBlock  *  * ```php  * echo('hi');  * ```  *  * @return ...  */ 
like image 115
Mat-Locomotive Avatar answered Sep 23 '22 15:09

Mat-Locomotive