fazy fazy - 7 months ago 11
PHP Question

How to "comment out" annotation entries in Doctrine

Given the following property with PHPDoc comment containing an annotation for Doctrine:

/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;


What is the best way to "comment out" one of the annotation lines? e.g. something like this:

/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* //Comment out please// @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;


Is there a supported way, or a general convention for doing this?

Answer

I usually add the @foo annotation (this class will not issue any problem) in order to comment out inside of dockblocks. You can register a global annotation for ignore:

AnnotationReader::addGlobalIgnoredName('foo');

This will be applied as:

/**
 * @Column(type="string", nullable=false, name="body")
 * @foo type="string", nullable=false, name="body2" 
 */
protected $body;

You can verify it at doctrine 2.1 documentation:

The @Foo annotation. It is not a documentation annotation and not blacklisted. For Doctrine Annotations it is not entirely clear how to handle this annotation. Depending on the configuration an exception (unknown annotation) will be thrown when parsing this annotation

According to quote below, the example should not throws any exception because the @foo annotation was registed previously

Comments