3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test1 { } $test1 = new test1(); $test1->foo->bar = 42; var_dump($test1); echo PHP_EOL . PHP_EOL; class test2 { public $foo; } $test2 = new test2(); $test2->foo->bar = 42; var_dump($test2); echo PHP_EOL . PHP_EOL; class test3 { } $test3 = new test3(); $test3->foo->bar['nope'] = 42; var_dump($test3); echo PHP_EOL . PHP_EOL; class test4 { public $foo; } $test4 = new test4(); $test4->foo->bar['nope'] = 42; var_dump($test4); echo PHP_EOL . PHP_EOL;
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Creation of dynamic property test1::$foo is deprecated in /in/aakSR on line 8 Fatal error: Uncaught Error: Attempt to assign property "bar" on null in /in/aakSR:8 Stack trace: #0 {main} thrown in /in/aakSR on line 8
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
Fatal error: Uncaught Error: Attempt to assign property "bar" on null in /in/aakSR:8 Stack trace: #0 {main} thrown in /in/aakSR on line 8
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Warning: Creating default object from empty value in /in/aakSR on line 8 object(test1)#1 (1) { ["foo"]=> object(stdClass)#2 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/aakSR on line 21 object(test2)#3 (1) { ["foo"]=> object(stdClass)#4 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/aakSR on line 33 object(test3)#5 (1) { ["foo"]=> object(stdClass)#6 (1) { ["bar"]=> array(1) { ["nope"]=> int(42) } } } Warning: Creating default object from empty value in /in/aakSR on line 46 object(test4)#7 (1) { ["foo"]=> object(stdClass)#8 (1) { ["bar"]=> array(1) { ["nope"]=> int(42) } } }
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33
Warning: Creating default object from empty value in /in/aakSR on line 8 object(test1)#1 (1) { ["foo"]=> object(stdClass)#2 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/aakSR on line 21 object(test2)#3 (1) { ["foo"]=> object(stdClass)#4 (1) { ["bar"]=> int(42) } } object(test3)#5 (1) { ["foo"]=> object(stdClass)#6 (1) { ["bar"]=> array(1) { ["nope"]=> int(42) } } } object(test4)#7 (1) { ["foo"]=> object(stdClass)#8 (1) { ["bar"]=> array(1) { ["nope"]=> int(42) } } }

preferences:
149.96 ms | 403 KiB | 155 Q