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 { public $foo; } $test3 = new test3(); $test3->foo->bar['nope'] = 42; var_dump($test3); echo PHP_EOL . PHP_EOL;
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Creation of dynamic property test1::$foo is deprecated in /in/ckkUh on line 8 Fatal error: Uncaught Error: Attempt to assign property "bar" on null in /in/ckkUh:8 Stack trace: #0 {main} thrown in /in/ckkUh on line 8
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Creation of dynamic property test1::$foo is deprecated in /in/ckkUh on line 8 Fatal error: Uncaught Error: Attempt to assign property "bar" on null in /in/ckkUh:8 Stack trace: #0 {main} thrown in /in/ckkUh on line 8
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught Error: Attempt to assign property "bar" on null in /in/ckkUh:8 Stack trace: #0 {main} thrown in /in/ckkUh 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/ckkUh on line 8 object(test1)#1 (1) { ["foo"]=> object(stdClass)#2 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/ckkUh on line 21 object(test2)#3 (1) { ["foo"]=> object(stdClass)#4 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/ckkUh on line 34 object(test3)#5 (1) { ["foo"]=> object(stdClass)#6 (1) { ["bar"]=> array(1) { ["nope"]=> int(42) } } }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Warning: Creating default object from empty value in /in/ckkUh on line 8 object(test1)#1 (1) { ["foo"]=> object(stdClass)#2 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/ckkUh 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) } } }

preferences:
172.17 ms | 403 KiB | 202 Q