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'));

preferences:
21.93 ms | 474 KiB | 4 Q