Question

I've seen this used (example from Doctrine2) in a lot of libraries that have code which works with comments:

<?php
namespace MyProject\Entities;

use Doctrine\ORM\Mapping AS ORM;
use Symfony\Component\Validation\Constraints AS Assert;

/**
 * @ORM\Entity
 * @MyProject\Annotations\Foobarable
 */
class User
{
    /**
     * @ORM\Id @ORM\Column @ORM\GeneratedValue
     * @dummy
     * @var int
     */
    private $id;
}

I seems as though some of the comment tags are "namespaced". Is this some PHP feature that I'm not aware of (since it seems to work with the "use" statements), or is it just some smart text parsing within the library that uses these?

I am asking because I am currently developing a small class that has to read some of this "metadata", and it would be really neat if this is something that is included in the language, so I don't have to write ugly text parsers.

Many thanks in advance.

Was it helpful?

Solution

No, its a feature to help IDE's like netbeans in there autocompletion and hinting when typing in the code.

If you want to do some docblock parsing, as a alternative you could use the reflection class, to get information about the class without parsing the docblocks (that could be inaccurate)

See this tutorial.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top