3v4l.org

run code in 500+ PHP versions simultaneously
<?php abstract class Operation { public function __construct( protected ?string $name = null, protected ?string $foo = null, ) {} } class Get extends Operation { public function __construct( ?string $name = null, ?string $bar = null, protected string $method = 'GET', ) { $params = (new ReflectionClass(self::class))->getMethod('__construct')->getParameters(); $a = []; foreach (func_get_args() as $i => $v) { $a[$params[$i]->getName()] = $v; } $args = []; foreach ((new ReflectionClass(parent::class))->getMethod('__construct')->getParameters() as $parameter) { $args[$name = $parameter->getName()] = $a[$name] ?? null; } call_user_func_array('parent::__construct', $args); } } var_dump(new Get(name: 'test', method: 'GET'));
Output for 8.0.1 - 8.0.30
object(Get)#1 (3) { ["method":protected]=> string(3) "GET" ["name":protected]=> string(4) "test" ["foo":protected]=> NULL }
Output for 8.1.0 - 8.1.34
object(Get)#1 (3) { ["name":protected]=> string(4) "test" ["foo":protected]=> NULL ["method":protected]=> string(3) "GET" }
Output for 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
Deprecated: Use of "parent" in callables is deprecated in /in/OFhko on line 32 object(Get)#1 (3) { ["name":protected]=> string(4) "test" ["foo":protected]=> NULL ["method":protected]=> string(3) "GET" }

preferences:
31.91 ms | 1144 KiB | 11 Q