What is the difference between "/ *" and "/ **" comments in PHP?

8

I've always been curious about this, but since I've never changed my life into anything, I've never tried to find out.

If there is a difference, what would be between these types of comments in PHP?

/* Comentário 1 */

/** Comentário 2 */
    
asked by anonymous 24.10.2015 / 20:11

2 answers

8

/* Comentário 1 */ , is a comment anyway with // or # . It's curious to note that no comment type overrides the closing thread ?>

/** Comentário 2 */ , is called doclet what is inside it, usually annotated with at @ is one or more information that some frameworks read to make the configuration of certain features easier, that way you do not have to configure some xml or external file.

If some configuration is mandatory and you forget the second asterisk, you will get a bit of a headache if you do not know this subtle difference.

See an example taken from symfony how to set up a route, can be done through an xml, yaml or php file.

class HelloController
{
    /**
     * @Route("/hello/{name}", name="hello")
     */
    public function indexAction($name)
    {
        return new Response('<html><body>Hello '.$name.'!</body></html>');
    }
}

This information can still be used by IDEs to provide a better autocomplete for example with setting the input or output parameter type and can be used to generate documentation.

    
24.10.2015 / 21:01
5

Comments with the second * can be used, for example, to generate documentation.

All the frameworks I know in PHP use the second * to later generate code documentation.

One tool for generating PHP code documentation is PHPDocumentor .

This saves a lot of time when writing documentation.

    
24.10.2015 / 20:35