kphp
kphp copied to clipboard
Inherited phpdoc is not applied if typehint is used (?)
<?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 []; }
}