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));
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
Fatal error: Uncaught AssertionError: assert(is_string($foo->bar)) in /in/TD3a6:21 Stack trace: #0 /in/TD3a6(21): assert(false, 'assert(is_strin...') #1 {main} thrown in /in/TD3a6 on line 21
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting variable (T_VARIABLE) in /in/TD3a6 on line 9
Process exited with code 255.

preferences:
70.03 ms | 407 KiB | 5 Q