我使用的是 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
.
最佳答案
我的错。
PHP 文档注释应以 /**
开头,但在我的类里面有时我使用 /*
这就是 getDocComment()
返回 false
的原因。
关于php - Symfony 和 ReflectionProperty::getDocComment() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16683388/