Using int in your doctrine entity will break symfony2

If you define your doctrine yml file using shorthand 'int' instead of 'integer', you will be in for a world of annoyances.

Suppose you create an entity named students, and one of the database fields is age. In the yml, you mave have done this:

  repositoryClass: YourApp\StudentBundle\Entity\StudentRepository
  type: entity
  table: students


      type: in


  lifecycleCallbacks: {  }

Without complaint, doctrine will generate your entities for you, but they will contain the following declaration:

 * @var int
function setAge(\int $age)

This is going to throw an error, when PHP comes across it and has no idea what the 'int' class is.

Always use 'integer'.

No comments:

Post a Comment