title: PHP 7 type declaration for symfony entities
body: <p>With PHP 7 type declarations can be used to throw an exception if the provided parameter has another type than expected. Can this be used to only allow symfony entities?</p>
  
  <pre><code>/**
   * @param User|MyOtherEntity $entity
   */
  public function serialize(TYPEHINTFORENTITY $entity)
  {
      $json = json_decode($this-&gt;serializer-&gt;serialize(
          $entity,
          'json'
      ), true);
  
      return $json;
  }
  
  public function deserialize($json, string $class): TYPEHINTFORENTITY
  {
      $entity = $this-&gt;serializer-&gt;deserialize(
          json_encode($json),
          'MyBundle\Entity\' . $class,
          'json',
          DeserializationContext::create()-&gt;setGroups(
              array('group')
          )
      );
  
      return $entity;
  }
  </code></pre>
  
  <p>If I use the same function to serialize different entities I can't use</p>
  
  <pre><code>public function serialize(User $entity)
  </code></pre>
  
  <p>because that wouldn't allow entities of MyOtherEntity to be serialized.</p>