Re: Proposal fo "Code-free constructors declaration"
| From: | Ivan Enderlin | Date: | Wed, 23 Jan 2019 12:48:14 +0000 |
| Subject: | Re: Proposal fo "Code-free constructors declaration" | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103794@lists.php.net to get a copy of this message | ||
On 23.01.19 13:32, Andrey O Gromov wrote:
Full description https://wiki.php.net/rfc/code_free_constructor Draft realisation https://github.com/php/php-src/compare/master...rjhdby:constructor "Code free" constructor is constructor with only purpose to directly set object properties from received parameters and, optionally, call parent constructor. Main idea is to move such constructor declaration inside class declaration. Simple example: Current syntax class A extends B{Hello and thanks for the RFC. I don't like the approach but I can change my mind. Currently, I see an issue with your RFC: How do you add types with this syntax? Given this syntax from the RFC: class MotorCycle($vendor, $cc){public $prop;public function __construct($prop){ parent::__construct("BlaBla", $prop); $this->prop = $prop; }} Proposed syntax class A($prop) extends B("BlaBla", $prop) { } With respect, Andrey.
public $whells = 2;
//other methods}; class MyCustomMotorCycle($cc, $whells) extends MotorCycle("Custom", $cc){ }; How do you say that
public $cc can be an integer for instance, so expressing this public int $cc?
Cheers.