Hello!

It is just an idea to discuss. PHP 8 now supports parameter promotion via
constructor. Could this idea also work for common methods?

public function setAge(private int $age) {}
===
private int $age;
public function setAge(int $age) { $this->age = $age; }

The only problem I can see would be the difficulty of identification of the
possible properties, since it would be necessary to check all method
signatures to know about all possible properties.

In this case, perhaps, it would be enough to allow the promotion only if
the property already exists.

private int $age; // Required.
public function setAge(private int $age) {}

Just to think about whether it is possible to think of something along
these lines, but I'm still not sure if it's a good option.


Atenciosamente,
David Rodrigues

Reply via email to