我使用的是PHP 5.4.15,MS windows Pro 64位,apache 2.4和Symfony 2.2。
有没有人注意到ReflectionProperty::getDocComment()
有时会无缘无故地返回false
?
我有一个Symfony项目,使用注解,有时注解就是不起作用。我还发现Symfony使用ReflectionProperty::getDocComment()
来获取注释,用于注释目的。
例如:
/**
*
* @ORM\Entity
* @ORM\Table(name="orders")
*
*/
class Order
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/** @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction") */
protected $paymentInstruction;
/** @ORM\Column(type="decimal", precision = 2) */
protected $amount;
}
当ReflectionProperty::getDocComment()
处理$amount
字段时,它返回的不是该字段的注释,而是false
。
如果我将该字段移到类的顶部,则不会处理$paymentInstruction
。
让注解生效的唯一方法是以特定的顺序(排列)移动类字段,并且ReflectionProperty::getDocComment()
不会返回false
。
发布于 2013-05-22 13:04:32
是我的错。
PHP文档注释应该以/**
开头,但在我的类中,有时我使用/*
,这就是getDocComment()
返回false
的原因。
https://stackoverflow.com/questions/16683388
复制相似问题