Psalm
Get started
Documentation
Plugins
Articles
GitHub
<?php class Animal {} class Dog extends Animal {} class Cat extends Animal {} /** * @template-covariant T */ class Collection { /** * @var array<int, T> */ public array $list; /** * @param array<int, T> $list */ public function __construct(array $list) { $this->list = $list; } /** * @param T $t */ public function add($t) : void { $this->list[] = $t; } } /** * @param Collection<Animal> $collection */ function addAnimal(Collection $collection) : void { $collection->add(new Cat()); } /** * @param Collection<Dog> $dog_collection */ function takesDogList(Collection $dog_collection) : void { addAnimal($dog_collection); }
Snippet created on December 19 2019 at 10:29 UTC
Settings
Get link