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?
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.
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.
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.
phpDocumentor is capable of automatically documenting include statements, define statements, functions, procedural pages, classes, class variables, and class methods.
phpdocumentor uses the github variant of markdown.
The proper way to add code, is then:
/** * This is a test DocBlock * * ```php * echo('hi'); * ``` * * @return ... */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With