I'm added an illustration. Maybe it more clear for understanding.
https://wiki.php.net/_detail/rfc/joined.png?id=rfc%3Acode_free_constructor

>> Proposed syntax
>> class A($prop) extends B("BlaBla", $prop) {
>> }

> This looks like unobvious magic. PHP approach has traditionally been to
> avoid unobvious magic, and be explicit about what is happening.
> This functionality does not seem no be enabling anything different, 
> and seems to be pretty obscure as to what is going on.
There is no magic, just alternative constructor syntax with some 
default behavior. Additional paragraph in documentation will resolve 
all obscurity.

Vice versa, this syntax make behavior more strict. No need to 
read constructor's body, because you know exactly what's going on.

Also there is no place for typos in boilerplate and refactoring errors.

IMHO inheritance also is more clear, because no need to search 
"parent::__construct" in the middle of class body.

> Also, $prop can not be documented this way, and assigning default 
> value to it may be a bit weird too.
Not sure that I understand this remark right way. What did you mean?
You can use php-doc similar you used it for functions.
Parameters block identical to function parameters block,
including types and default values.

> I am all for paving the walkways, but this particular case
> seems to be a bit too narrow to have a special language syntax for, and
> the syntax seems to be not exactly obvious as to what's going on there.
Matter of quality of documentation.

----------------------------
To Levi Morrison and Bruce Weirdan.

>> Would this work with anonymous classes? If so, how would the syntax 
look like?
> I have the same question. I don't think it would work with them, but I
> could be wrong.

There is no big problem to add same functionality to anonymous classes.
But unfortunately only possible syntax(I think) is not very nice.

new class(string $a, int $b, int $c=15)("Hi!",  20) extends SomeClass($a, 
115){...}

Reply via email to