3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $a; function __construct($a) { $this->a = $a; } public function getA() { return $this->a; } } class B extends A { function __construct() { parent::__construct('foo'); } } var_dump($b = new B); class C extends A { function __construct(A $a) { $a->a = 'bar'; $this->a = 'baz'; } } var_dump(new C($b)); var_dump($b->getA());
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
object(B)#1 (1) { ["a":"A":private]=> string(3) "foo" } Deprecated: Creation of dynamic property B::$a is deprecated in /in/5VPVV on line 25 Deprecated: Creation of dynamic property C::$a is deprecated in /in/5VPVV on line 26 object(C)#2 (2) { ["a":"A":private]=> NULL ["a"]=> string(3) "baz" } string(3) "foo"
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 object(B)#1 (1) { ["a":"A":private]=> string(3) "foo" } Deprecated: Creation of dynamic property B::$a is deprecated in /in/5VPVV on line 25 Deprecated: Creation of dynamic property C::$a is deprecated in /in/5VPVV on line 26 object(C)#2 (2) { ["a":"A":private]=> NULL ["a"]=> string(3) "baz" } string(3) "foo"
Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.33, 7.2.6 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
object(B)#1 (1) { ["a":"A":private]=> string(3) "foo" } object(C)#2 (2) { ["a":"A":private]=> NULL ["a"]=> string(3) "baz" } string(3) "foo"

preferences:
186.25 ms | 403 KiB | 210 Q