Method parameter promotion support

From: Date: Thu, 26 Nov 2020 16:30:23 +0000
Subject: Method parameter promotion support
Groups: php.internals 
Request: Send a blank email to internals+get-112298@lists.php.net to get a copy of this message
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

« previous php.internals (#112298) next »