3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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;
based on ckkUh
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.21.3, 7.0.0 - 7.2.6
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) } } }
Output for hhvm-3.22.0
Warning: Creating default object from empty value in /in/aakSR on line -1 object(test1)#1 (1) { ["foo"]=> object(stdClass)#2 (1) { ["bar"]=> int(42) } } Warning: Creating default object from empty value in /in/aakSR on line -1 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) } } }