rfc:constructor_return_type
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:constructor_return_type [2020/06/15 23:47] – initial RFC moliata | rfc:constructor_return_type [2020/06/17 10:01] – old revision restored (2020/06/16 21:14) cmb | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Allow void return type on constructors/ | ====== PHP RFC: Allow void return type on constructors/ | ||
* Date: 2020-06-16 | * Date: 2020-06-16 | ||
- | * Author: Benas Seliuginas < | + | * Author: Benas Seliuginas, < |
* Target version: PHP 8.0 | * Target version: PHP 8.0 | ||
- | * Status: | + | * Status: |
===== Introduction ===== | ===== Introduction ===== | ||
Line 11: | Line 11: | ||
===== Proposal ===== | ===== Proposal ===== | ||
+ | The introduction sums up the entire proposal therefore I provided a few arguments and thoughts of mine, as to why we should allow this " | ||
==== Explicit declaration ==== | ==== Explicit declaration ==== | ||
Since a fix for bug #79679 [[https:// | Since a fix for bug #79679 [[https:// | ||
Line 46: | Line 47: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | Moreover, it's important to remember that the constructor is rather a regular function that can be called just like any other method (i.e. '' | ||
==== Documented as void ==== | ==== Documented as void ==== | ||
Line 51: | Line 54: | ||
==== __clone allows void return type ==== | ==== __clone allows void return type ==== | ||
- | ... | + | Given that the [[https:// |
+ | |||
+ | <code php> | ||
+ | <? | ||
+ | ... | ||
+ | |||
+ | $object = new Test(); | ||
+ | // | ||
+ | // and works similarly to a constructor but | ||
+ | // will indeed allow the void return type. | ||
+ | $object_2 = clone $object; | ||
+ | </ | ||
==== Consistency with other methods ==== | ==== Consistency with other methods ==== | ||
- | ... | + | Basically, all (both regular and magic) methods allow to have an explicit return type. The only exceptions are constructors and destructors. |
+ | As [[https:// | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== |
rfc/constructor_return_type.txt · Last modified: 2020/06/17 10:04 by cmb