On Thu, Mar 26, 2020 at 5:02 PM David Rodrigues <david.pro...@gmail.com> wrote:
> Hello! > > With all respect, seems a bit confuses to me, without in fact offer a new > feature, just a shortcut. I hope it's me seeing it the wrong way. > > What happen if I rename the constructor parameters on a child class > constructor? > > Example (https://3v4l.org/VqQde): > > class A { > public function __construct(public int $x) { ... } > } > > class B extends A { > public function __construct(public int $y) { ...; > parent::__construct($y); } > } > Constructors (in general, independent of this feature) are per-class and do not participate in classical signature-based inheritance (the exception being abstract constructors, but those aren't relevant here). The notion of "renaming" a constructor parameter doesn't make sense in that regard, because the parameters of the child constructor have absolutely no relation to the parameters of the parent constructor. The way to write your example would be: class A { public function __construct(public int $x) {} } class B extends A { public function __construct(int $x) { parent::__construct($x); // Your extra logic here. } } Regards, Nikita