3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function add($val = 0) { $this->stuff[] = $val; } } $x = new Foo(); $x->add(42); echo serialize($x) . "\n"; var_dump($x); echo "\n\n"; class Bar { private $stuff = []; public function add($x = 0) { $this->stuff[] = $x; } } $x = new Bar(); $x->add(42); echo serialize($x) . "\n"; var_dump($x);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Creation of dynamic property Foo::$stuff is deprecated in /in/fCs2s on line 5 O:3:"Foo":1:{s:5:"stuff";a:1:{i:0;i:42;}} object(Foo)#1 (1) { ["stuff"]=> array(1) { [0]=> int(42) } } O:3:"Bar":1:{s:10:"Barstuff";a:1:{i:0;i:42;}} object(Bar)#2 (1) { ["stuff":"Bar":private]=> array(1) { [0]=> int(42) } }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28
O:3:"Foo":1:{s:5:"stuff";a:1:{i:0;i:42;}} object(Foo)#1 (1) { ["stuff"]=> array(1) { [0]=> int(42) } } O:3:"Bar":1:{s:10:"Barstuff";a:1:{i:0;i:42;}} object(Bar)#2 (1) { ["stuff":"Bar":private]=> array(1) { [0]=> int(42) } }

preferences:
123.36 ms | 402 KiB | 121 Q