3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Collection { /** @var string */ private $type; /** * @param string $type * @return Collection */ public static function ofType($type) { $collection = new static(); $collection->type = $type; $class = explode('\\', $type); class_alias(self::class, sprintf('%sCollection', array_pop($class))); return $collection; } } final class Person {} $col = Collection::ofType(Person::class); function parsePersonCollection(PersonCollection $coll) { } parsePersonCollection($col);

preferences:
44.25 ms | 402 KiB | 5 Q