Psalm
Get started
Documentation
Plugins
Articles
GitHub
<?php abstract class Animal { abstract public function getNoise() : string; } class Dog extends Animal { public function getNoise() : string { return "woof"; } } class Cat extends Animal { public function getNoise() : string { return "miaow"; } } /** * @template-covariant T */ class Collection { /** @var array<int, T> */ public array $list = []; } /** * @param Collection<Animal> $collection */ function getNoises(Collection $collection) : void { foreach ($collection->list as $animal) { echo $animal->getNoise(); } } /** * @param Collection<Dog> $dog_collection */ function takesDogList(Collection $dog_collection) : void { getNoises($dog_collection); }
Snippet created on December 19 2019 at 10:27 UTC
Settings
Get link