3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Papa { public function __construct() { $args = func_get_args(); echo print_r($args, true); } } class Kiddo extends Papa { public function __construct() { $args = func_get_args(); $parent_class = 'parent'; if (version_compare(PHP_VERSION, '5.5.0') >= 0) { $parent_class = parent::class; } call_user_func_array(array($parent_class, '__construct'), $args); } } $x = new Papa('bee'); $y = new Kiddo('hello', 'me');
Output for 8.1.23 - 8.1.30, 8.2.6 - 8.2.25, 8.3.0 - 8.3.13
Array ( [0] => bee ) Array ( [0] => hello [1] => me )
Output for 5.4.0
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/E9eTR on line 15
Process exited with code 255.

preferences:
49.26 ms | 406 KiB | 5 Q