title: Symfony 4 : "must implement interface DateTimeInterface" Error
body: <p>I'm creating an admin with easy admin bundle, i'm really new to Symfony4.</p>
  
  <p>I've a button "create a category" and when i click on it, I've this error :</p>
  
  <blockquote>
    <p>Return value of App\Entity\Category::getCreatedAt() must implement interface DateTimeInterface, null returned</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use DateInterval;
  use DateTimeZone;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use DateTimeInterface;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\CategoryRepository")
   */
  class Category
  {
  
      use TimestampableTrait;
  
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=8)
       */
      private $ref;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="categoryId")
       */
      private $products;
  
      /**
       * Category constructor.
       */
      public function __construct()
      {
          $this-&gt;products = new ArrayCollection();
      }
  
      /**
       * @return int|null
       */
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      /**
       * @return string|null
       */
      public function getRef(): ?string
      {
          return $this-&gt;ref;
      }
  
      /**
       * @param string $ref
       * @return $this
       */
      public function setRef(string $ref): self
      {
          $this-&gt;ref = $ref;
  
          return $this;
      }
  
      /**
       * @return Collection|Product[]
       */
      public function getProducts(): Collection
      {
          return $this-&gt;products;
      }
  
      /**
       * @param Product $product
       * @return $this
       */
      public function addProduct(Product $product): self
      {
          if (!$this-&gt;products-&gt;contains($product)) {
              $this-&gt;products[] = $product;
              $product-&gt;setCategoryId($this);
          }
  
          return $this;
      }
  
      /**
       * @param Product $product
       * @return $this
       */
      public function removeProduct(Product $product): self
      {
          if ($this-&gt;products-&gt;contains($product)) {
              $this-&gt;products-&gt;removeElement($product);
              // set the owning side to null (unless already changed)
              if ($product-&gt;getCategoryId() === $this) {
                  $product-&gt;setCategoryId(null);
              }
          }
  
          return $this;
      }
  
      /**
       * (PHP 5 &amp;gt;=5.5.0)&lt;br/&gt;
       * Returns the difference between two DateTime objects
       * @link https://secure.php.net/manual/en/datetime.diff.php
       * @param DateTimeInterface $datetime2 &lt;p&gt;The date to compare to.&lt;/p&gt;
       * @param bool $absolute &lt;p&gt;Should the interval be forced to be positive?&lt;/p&gt;
       * @return DateInterval
       * The https://secure.php.net/manual/en/class.dateinterval.php DateInterval} object representing the
       * difference between the two dates or &lt;b&gt;FALSE&lt;/b&gt; on failure.
       *
       */
      public function diff($datetime2, $absolute = false)
      {
          // TODO: Implement diff() method.
      }
  
      /**
       * (PHP 5 &amp;gt;=5.5.0)&lt;br/&gt;
       * Returns date formatted according to given format
       * @link https://secure.php.net/manual/en/datetime.format.php
       * @param string $format &lt;p&gt;
       * Format accepted by  {@link https://secure.php.net/manual/en/function.date.php date()}.
       * &lt;/p&gt;
       * @return string
       * Returns the formatted date string on success or &lt;b&gt;FALSE&lt;/b&gt; on failure.
       *
       */
      public function format($format)
      {
          // TODO: Implement format() method.
      }
  
      /**
       * (PHP 5 &amp;gt;=5.5.0)&lt;br/&gt;
       * Returns the timezone offset
       * @return int
       * Returns the timezone offset in seconds from UTC on success
       * or &lt;b&gt;FALSE&lt;/b&gt; on failure.
       *
       */
      public function getOffset()
      {
          // TODO: Implement getOffset() method.
      }
  
      /**
       * (PHP 5 &amp;gt;=5.5.0)&lt;br/&gt;
       * Gets the Unix timestamp
       * @return int
       * Returns the Unix timestamp representing the date.
       */
      public function getTimestamp()
      {
          // TODO: Implement getTimestamp() method.
      }
  
      /**
       * (PHP 5 &amp;gt;=5.5.0)&lt;br/&gt;
       * Return time zone relative to given DateTime
       * @link https://secure.php.net/manual/en/datetime.gettimezone.php
       * @return DateTimeZone
       * Returns a {@link https://secure.php.net/manual/en/class.datetimezone.php DateTimeZone} object on success
       * or &lt;b&gt;FALSE&lt;/b&gt; on failure.
       */
      public function getTimezone()
      {
          // TODO: Implement getTimezone() method.
      }
  
      /**
       * (PHP 5 &amp;gt;=5.5.0)&lt;br/&gt;
       * The __wakeup handler
       * @link https://secure.php.net/manual/en/datetime.wakeup.php
       * @return void Initializes a DateTime object.
       */
      public function __wakeup()
      {
          // TODO: Implement __wakeup() method.
      }
  }
  </code></pre>
  
  <p>My TimestampableTrait</p>
  
  <pre><code>    &lt;?php
  
  namespace App\Entity;
  
  /**
   * You must add the following comment on all the entities:
   * @ORM\HasLifecycleCallbacks()
   */
  trait TimestampableTrait
  {
  
      /**
       * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="createdBy")
       * @ORM\JoinColumn(nullable=true)
       */
      protected $createdBy;
  
      /**
       * @return User|null
       */
      public function getCreatedBy(): ?User
      {
          return $this-&gt;createdBy;
      }
  
      /**
       * @param User|null $createdBy
       * @return $this
       */
      public function setCreatedBy(?User $createdBy): self
      {
          $this-&gt;createdBy = $createdBy;
  
          return $this;
      }
  
      /**
       * @var \DateTime
       * @ORM\Column(type="datetime", nullable=true)
       */
      protected $createdAt;
  
      /**
       * @var \DateTime
       * @ORM\Column(type="datetime", nullable=false)
       */
      protected $updatedAt;
  
      /**
       * Set the created at value on create
       * @ORM\PrePersist()
       * @param \DateTimeInterface $createdAt
       * @return self
       */
      public function setCreatedAt(\DateTimeInterface $createdAt): self
      {
          $this-&gt;createdAt = $createdAt;
          return $this;
      }
  
      /**
       * Set the updated at value on update
       * @ORM\PrePersist()
       * @ORM\PreUpdate()
       * @param \DateTimeInterface $updatedAt
       * @return self
       */
      public function setUpdatedAt(\DateTimeInterface $updatedAt): self
      {
  
          $this-&gt;updatedAt = $updatedAt;
  
          return $this;
      }
  
      /**
       * Get - Created At
       *
       * @return \DateTimeInterface
       */
      public function getCreatedAt(): \DateTimeInterface
      {
          return $this-&gt;createdAt;
      }
  
      /**
       * Get - Updated At
       *
       * @return \DateTimeInterface|null
       */
      public function getUpdatedAt(): \DateTimeInterface
      {
          return $this-&gt;updatedAt;
      }
  
  }
  </code></pre>
  
  <p>I really don't get where is the problem.</p>