-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Labels
Milestone
Description
class Dog {}
/**
* @template T
*/
class Collection {
/** @var array<T> */
protected $arr = [];
/**
* @param array<T> $arr
*/
public function __construct(array $arr) {
$this->arr = $arr;
}
/**
* @return T
*/
public function last()
{
if (!$this->arr) {
throw new \Exception('bad');
}
return end($this->arr);
}
}
/**
* @template T
* @extends Collection<T>
*/
class CollectionChild extends Collection {
}
// inferred as Collection<Dog>
$dogs = new Collection([new Dog(), new Dog()]);
echo $dogs->last(); // error
// inferred as CollectionChild<mixed>
$dogs = new CollectionChild([new Dog(), new Dog()]);
echo $dogs->last(); // no errorRelated to #845, as this would be more obvious (without need for echo)
Reactions are currently unavailable