<?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'));
You have javascript disabled. You will not be able to edit any code.