3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public int $a; public string $b; public DateTime $c; } $foo = new Foo; $foo->a = "42"; // a will contain int(42) $foo->b = 42; // b will contain string("42") var_dump($foo); $foo->c = 12345; // will error
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
object(Foo)#1 (2) { ["a"]=> int(42) ["b"]=> string(2) "42" ["c"]=> uninitialized(DateTime) } Fatal error: Uncaught TypeError: Cannot assign int to property Foo::$c of type DateTime in /in/bmZ0H:14 Stack trace: #0 {main} thrown in /in/bmZ0H on line 14
Process exited with code 255.
Output for 7.4.0 - 7.4.33
object(Foo)#1 (2) { ["a"]=> int(42) ["b"]=> string(2) "42" ["c"]=> uninitialized(DateTime) } Fatal error: Uncaught TypeError: Typed property Foo::$c must be an instance of DateTime, int used in /in/bmZ0H:14 Stack trace: #0 {main} thrown in /in/bmZ0H on line 14
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/bmZ0H on line 3
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting variable (T_VARIABLE) in /in/bmZ0H on line 3
Process exited with code 255.

preferences:
100.24 ms | 2174 KiB | 4 Q