4
votes

I created a doctrine annotation

namespace Fondative\GenBundle\Front\Annotation;
use Doctrine\Common\Annotations\Annotation;

/**
* @Annotation
* @Target("PROPERTY")
*/
class ReferenceAnnotation extends Annotation {

}

use Fondative\GenBundle\Front\Annotation\ReferenceAnnotation ;

/**
 * A Driver.
 * 
 *
 * 
 * @ORM\Entity
 * 
 */
class Driver {
    /*
     * @Reference
     */
    private $name;

I get this exception

[Semantical Error] The annotation "@Reference" in property Fondative\TestBundle\Entity\Driver::$name was never imported.

2
try with this use statement: use Fondative\GenBundle\Front\Annotation\ReferenceAnnotation as Reference;Matteo
I was calling the wrong annotation name :user5913178

2 Answers

0
votes

A very common mistake ;)

The package Doctrine/Annotation read annotations from comments via ReflectionProperty::getDocComment().

Problem example:

class MyClassA
{
    /**
     * Foo
     */
    private $foo;

    /*
     * Bar
     */
    private $bar;
}


$ref = new \ReflectionClass('MyClassA');

print sprintf(
    "Comment of MyClassA::foo -> \n%s\n\n",
    $ref->getProperty('foo')->getDocComment()
);

print sprintf(
    "Comment of MyClassA::bar -> \n%s\n\n",
    $ref->getProperty('bar')->getDocComment()
);

The property foo have a doc comments, but property bar not have comment, because exist typos in declare comment (one special char *).

In PHP doc comments must be started from two chars *!

Fix this typo, and all works ;)

0
votes
class Driver {
    /*
     * @ReferenceAnnotation
     */
    private $name;

or rename the annotation class to Reference and

use Fondative\GenBundle\Front\Annotation\Reference as Reference ;
     /*
     * @Reference
     */
    private $name;