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{
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.
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 $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.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php