3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public function __construct( public readonly \StdClass $obj = new \StdClass() ) {} } $a = new A(); $a->obj->hello = "world"; var_dump($a);
Output for 8.1.22 - 8.1.34, 8.2.9 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
object(A)#1 (1) { ["obj"]=> object(stdClass)#2 (1) { ["hello"]=> string(5) "world" } }
Output for 8.0.30
Parse error: syntax error, unexpected fully qualified name "\StdClass", expecting variable in /in/9ftoX on line 5
Process exited with code 255.

preferences:
59.96 ms | 751 KiB | 4 Q