title: PHP: "Declaration of ... should be compatible with that of ..."
body: <p>I'd like to create an interface for entities that are CRUDable (can be saved and deleted). Here is my abstract class:</p>
  
  <pre><code>abstract class AbstractCrudableEntity extends AbstractEntity
  {
      abstract public function doSave();
      abstract public function doDelete();
  }
  </code></pre>
  
  <p>My implementing class needs a couple extra parameters to those methods. Here is the signature of the implementing class:</p>
  
  <pre><code>class Contact extends AbstractCrudableEntity {
      public function doSave(User $user, \UberClientManager $manager);
      public function doDelete(User $user, \UberClientManager $manager);
  }
  </code></pre>
  
  <p>I understand that PHP requires that implementing classes have the same parameters for the methods as the parent class (there are several questions that answer this question: <a href="https://stackoverflow.com/questions/3115388/declaration-of-methods-should-be-compatible-with-parent-methods-in-php">this</a>, for example). So that is not the problem.</p>
  
  <p>However, I recently came across some code in Symfony dealing with authentication tokens. The class <code>UsernamePasswordToken</code> extends <code>AbstractToken</code>, and has a different set of parameters in the <code>__construct()</code> method: <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php#L38" rel="nofollow noreferrer"><code>AbstractToken::__construct()</code></a> versus <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php#L34" rel="nofollow noreferrer"><code>UsernamePasswordToken::__construct()</code></a>.</p>
  
  <p>My question is how is Symfony able to do this? What is the difference between this and my code?</p>