rfc:code_free_constructor

This is an old revision of the document!


PHP RFC: Code free constructor

Introduction

Mainly “code free” constructors used for declaration of DTO-classes. Also, some developers believe that it is good OOP-practice. Unfortunately they looks like unnecessary boilerplate.

Proposal

Proposal is to add alternate syntax for “code free” constructors. Current syntax:

class Test{
    public function __construct($first, $second){
        $this->first  = $first;
        $this->second = $second;
    }
    ...
}

Proposed syntax:

class Test($first, $second){
    ...
}

Backward Incompatible Changes

No.

Proposed PHP Version(s)

PHP 8.x

RFC Impact

Not thinking so

Future Scope

Deal with parent's constructor call

Implementation

Draft implementation, need to be reviewed. https://github.com/rjhdby/php-src/tree/constructor

References

rfc/code_free_constructor.1547650312.txt.gz · Last modified: 2019/01/16 14:51 by rjhdby