kphp icon indicating copy to clipboard operation
kphp copied to clipboard

Inherited phpdoc is not applied if typehint is used (?)

Open quasilyte opened this issue 4 years ago • 0 comments

<?php

class Foo{}

abstract class A {
  /** @return Foo[] */
  public abstract function f() : array;
}

class B extends A {
  public function f() : array { return []; }
}

function test() {
  $b = new B();
  $a = $b->f(); // $a has type array< Unknown >
  var_dump(count($a));
}

test();

It looks like we could use inherited phpdocs more willingly here.

With derived signatures checking enabled, the code above would not compile, so we would have to add an explicit @return annotation:

class B extends A {
+ /** @return Foo[] */
  public function f() : array { return []; }
}

quasilyte avatar Mar 22 '21 14:03 quasilyte