rfc:code_free_constructor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:code_free_constructor [2019/01/23 12:09] rjhdbyrfc:code_free_constructor [2019/01/28 07:18] rjhdby
Line 4: Line 4:
   * Author: Andrey Gromov, andrewgrom@rambler.ru, rjhdby@php.net   * Author: Andrey Gromov, andrewgrom@rambler.ru, rjhdby@php.net
   * Proposed version: PHP 8   * Proposed version: PHP 8
-  * Status: Pre draft+  * Status: draft
   * First Published at: https://wiki.php.net/rfc/code_free_constructor   * First Published at: https://wiki.php.net/rfc/code_free_constructor
   * ML thread: -   * ML thread: -
Line 55: Line 55:
 class MyCustomMotorCycle($cc, $whells) extends MotorCycle("Custom", $cc){ }; class MyCustomMotorCycle($cc, $whells) extends MotorCycle("Custom", $cc){ };
 </code> </code>
 +
 +{{:rfc:joined.png?400|}}
 +
 +By the way, current realization simply add "_ _construct" method into class via AST injection. 
 +Another words, code "($cc, $whells)" considered  as zend_ast node "parameter_list" and accordingly processed by standart way. You can declare property type like you declare them inside standard method. Also you can declare defaults for parameters, use "..." notation (there is a nuance) and do everything else.
 +
 +<code php>
 +class MyCustomMotorCycle(int $cc, int $whells = 3, ...$otherParams) extends MotorCycle("Custom", $cc){ };
 +</code>
 +
 +===== Restrictions =====
 +This syntax can't be used with anonymous classes because those classes instantiated at once they declared and same syntax is used for forwarding parameters directly into constructor.
  
 ===== Possible Issue ===== ===== Possible Issue =====
Line 101: Line 113:
  
 Draft implementation, need to be reviewed. Draft implementation, need to be reviewed.
-https://github.com/php/php-src/compare/master...rjhdby:constructor+https://github.com/rjhdby/php-src/compare/master...rjhdby:constructor
  
 ===== References ===== ===== References =====
  
  
rfc/code_free_constructor.txt · Last modified: 2019/01/29 12:17 by rjhdby