0

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.

4

1 回答 1

1

不,它的一个功能可以帮助像 netbeans 这样的 IDE 在输入代码时自动完成和提示。

如果您想做一些文档块解析,作为替代方案,您可以使用反射类来获取有关该类的信息而不解析文档块(这可能不准确)

请参阅本教程

于 2012-09-21T10:26:58.233 回答