DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

Symfony2 assign property throws parse error

/**
 * @ORM\Column(type="datetime", name="created_at")
*/
protected $createdAt = new DateTime();

This is the critical part of my entity definition where the parser raises an error:

Parse error: parse error in ...

when I execute

php app/console doctrine:schema:update --force

Whats wrong about this? The createdAt field should be assigned when the entity is first created. I am on symfony2.5.

Upvotes: 0

Views: 36

Answers (1)

Shazbot
Shazbot

Reputation: 380

Put the assignment to the property in the constructor. You can't assign a new object in that way.

public function __construct()
{
    $this->createdAt = new \DateTime();
}

Upvotes: 4

Related Questions