3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @template T of int|numeric-string */ class Foo { /** @param T $bar */ public function __construct(public $bar) {} } function bar(Foo $foo): void { $foo->bar = 123; } /** @var Foo<numeric-string> $foo */ $foo = new Foo("123"); bar($foo); assert(is_string($foo->bar));

preferences:
25.25 ms | 408 KiB | 6 Q