3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('display_errors', true); error_reporting(E_ALL); abstract class papa { public function papa() { var_dump(__CLASS__ . '-' . __FUNCTION__); } } class son extends papa { public function son() { var_dump(__CLASS__ . '-' . __FUNCTION__); parent::__construct(); } } abstract class mama { public function __construct() { var_dump(__CLASS__ . '-' . __FUNCTION__); } public function mama() { var_dump(__CLASS__ . '-' . __FUNCTION__); } } class daughter1 extends mama { public function daughter() { var_dump(__CLASS__ . '-' . __FUNCTION__); parent::__construct(); } } class daughter2 extends mama { public function daughter() { var_dump(__CLASS__ . '-' . __FUNCTION__); parent::mama(); } } var_dump('DAUGHTER calls parent::__construct'); $girl1 = new daughter1(); var_dump('DAUGHTER calls parent::mama'); $girl2 = new daughter2(); var_dump('SON'); $boy = new son();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
string(34) "DAUGHTER calls parent::__construct" string(16) "mama-__construct" string(27) "DAUGHTER calls parent::mama" string(16) "mama-__construct" string(3) "SON"
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 string(34) "DAUGHTER calls parent::__construct" string(16) "mama-__construct" string(27) "DAUGHTER calls parent::mama" string(16) "mama-__construct" string(3) "SON"
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; papa has a deprecated constructor in /in/sv32G on line 6 Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; son has a deprecated constructor in /in/sv32G on line 12 string(34) "DAUGHTER calls parent::__construct" string(16) "mama-__construct" string(27) "DAUGHTER calls parent::mama" string(16) "mama-__construct" string(3) "SON" string(7) "son-son" string(9) "papa-papa"
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.3.32 - 7.3.33
string(34) "DAUGHTER calls parent::__construct" string(16) "mama-__construct" string(27) "DAUGHTER calls parent::mama" string(16) "mama-__construct" string(3) "SON" string(7) "son-son" string(9) "papa-papa"

preferences:
144.59 ms | 402 KiB | 183 Q