18

I am getting this error in my annotations docblock for Doctrine 2:

Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected PlainValue, got ')'

After looking for an answer I found this reference Stackoverflow Question 3500125 which in essence says to put quotes around all values in annotations.

With the annotation block I have this does not seem possible. here is my example that is throwing the error.

/**
 * @var tags
 *
 * @ManyToMany(targetEntity="namespace\to\tag")
 * @JoinTable(name="content_tag",
 *   joinColumns={
 *     @JoinColumn(name="content_id", referencedColumnName="id")
 *   },
 *   inverseJoinColumns={
 *     @JoinColumn(name="tag_id", referencedColumnName="id")
 *   }
 * ) // This is the line indicated by the error
 */
private $tags;

If I follow the advice of the answer I found in stack overflow which is to quote out the values, my code will be like this:

/**
 * @var tags
 *
 * @ManyToMany(targetEntity="namespace\to\tag")
 * @JoinTable(name="content_tag",
 *   joinColumns="{
 *     @JoinColumn(name="content_id", referencedColumnName="id")
 *   }",
 *   inverseJoinColumns="{
 *     @JoinColumn(name="tag_id", referencedColumnName="id")
 *   }" // Note the extra quotation marks
 * )
 */
private $tags;

Which is not right at all.

Community
  • 1
  • 1
potsed
  • 351
  • 1
  • 2
  • 12
  • I have a many-to-many using the same syntax as you've got, the only differences being my indentation/placement and a cascade. Take a look: https://gist.github.com/1025638 – Jeremy Hicks Jun 14 '11 at 19:21
  • Thanks Jeremy, I am sure the syntax is right. but I still get the error. It is becoming very frustrating lol – potsed Jun 15 '11 at 00:24
  • The first code blocks looks valid and works for me. What version of Doctrine are you using? – Michael Ridgway Jun 17 '11 at 15:37
  • Sorry for the late reply, i found the error in my ways... and it is working now. See the answer below. To answer your question it was the 2.0.* stable release. – potsed Jun 23 '11 at 02:10

3 Answers3

74

For people who have come here but not because of doctrine, my mistake was using single quotes instead of double quotes in the @Routes annotation.

WRONG:

/**
* @Route('/home')
*/

RIGHT

/**
* @Route("/home")
*/
Kinjal Dixit
  • 7,777
  • 2
  • 59
  • 68
4

It was a silly mistake, the error string was not very helpful as it pointed to the line i showed in my question as the line that the error was on. The fact was that this entity was extending a parent object, the parent had the @Entity tag but the child did not, i moved it and everything works fine.

potsed
  • 351
  • 1
  • 2
  • 12
1

I Just had the same kind of error by using an assert for an entity :

     * @Assert\Email(
     *     message = "The email '{{ value }}' is not a valid email.",
     *     mode = 'strict',
     *     normalizer = 'trim'
     * )

Turning it into

     * @Assert\Email(
     *     message = "The email '{{ value }}' is not a valid email.",
     *     mode = "strict",
     *     normalizer = "trim"
     * )

Fixed it :)

Dennis de Best
  • 1,078
  • 13
  • 30