rfc:code_free_constructor
This is an old revision of the document!
PHP RFC: Code free constructor
- Version: 0.1
- Date: 2019-01-14
- Author: Andrey Gromov, andrewgrom@rambler.ru, rjhdby@php.net
- Proposed version: PHP 8
- Status: Pre draft
- First Published at: https://wiki.php.net/rfc/code_free_constructor
- ML thread: -
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/php/php-src/compare/master...rjhdby:constructor?expand=1
References
rfc/code_free_constructor.1547544006.txt.gz · Last modified: 2019/01/15 09:20 by rjhdby