title: PHP Covariance with inherited class - Declarations incompatibles
body: <p>I would like create an abstract class with abstract method which allow abstract type in return type. In my final class, I would like override type returned with type which implement abstract type initially declared.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  abstract class A {
      abstract public function test(A $foo): self;
  }
  
  class B extends A {
      public function test(B $foo): self
      {
          return $this;
      }
  }
  </code></pre>
  
  <p>This compilation error is thrown:</p>
  
  <pre class="lang-sh prettyprint-override"><code>Fatal error: Declaration of B::test(B $foo): B must be compatible with A::test(A $foo): A in ... on line 8
  </code></pre>
  
  <p><a href="https://www.php.net/manual/en/language.oop5.variance.php#language.oop5.variance.covariance" rel="nofollow noreferrer">In documentation, covariance is explained with interface.</a> But not with abstract class. More about PHP implementation, the documentation say:</p>
  
  <blockquote>
    <p>In PHP 7.2.0, partial contravariance was introduced by removing type restrictions on parameters in a child method. As of PHP 7.4.0, full covariance and contravariance support was added. </p>
  </blockquote>
  
  <p>I'm using PHP 7.4.</p>