Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
rfc:write_once_properties [2020/03/17 09:08] kocsismate |
rfc:write_once_properties [2020/03/31 07:51] kocsismate Closed the vote |
* Author: Máté Kocsis <kocsismate@php.net> | * Author: Máté Kocsis <kocsismate@php.net> |
* Target Version: PHP 8.0 | * Target Version: PHP 8.0 |
* Status: Under Discussion | * Status: Declined |
* Implementation: https://github.com/php/php-src/pull/5186 | * Implementation: https://github.com/php/php-src/pull/5186 |
| |
| |
class Foo { | class Foo { |
public int $a = 0; | <keyword> public int $a = 0; |
} | } |
| |
Finally, "write-once" properties could in principle support covariance. That is, a subclass would be allowed to tighten the property type that is inherited from the parent class, while other properties must stay invariant. All this would be possible because of the quasi-immutable nature of "write-once" properties: they are generally expected to be assigned to only once, in the constructor - which is exempt from LSP checks. There is a gotcha though: in practice, "write-once" properties could be written from places other than the constructor. Although there might not be many practical use-cases for it, the infamous setter injection is certainly one (as shown at https://3v4l.org/DQ3To), in which case property covariance would be a problem. | Finally, "write-once" properties could in principle support covariance. That is, a subclass would be allowed to tighten the property type that is inherited from the parent class, while other properties must stay invariant. All this would be possible because of the quasi-immutable nature of "write-once" properties: they are generally expected to be assigned to only once, in the constructor - which is exempt from LSP checks. There is a gotcha though: in practice, "write-once" properties could be written from places other than the constructor. Although there might not be many practical use-cases for it, the infamous setter injection is certainly one (as shown at https://3v4l.org/DQ3To), in which case property covariance would be a problem. |
| |
===== Proposed Voting Choices ===== | ===== Vote ===== |
The primary vote ("Do you want to add support for the proposed property modifier?") requires 2/3 majority, while the secondary one ("Which keyword to use"?) requires a simple majority. | |
| The vote starts on 2020-03-17 and ends on 2020-03-31. The primary vote requires 2/3, while the secondary one requires a simple majority to be accepted. |
| |
| <doodle title="Do you want to add support for write-once properties?" auth="kocsismate" voteType="single" closed="true"> |
| * Yes |
| * No |
| </doodle> |
| |
| ---- |
| |
| <doodle title="Which keyword to use?" auth="kocsismate" voteType="single" closed="true"> |
| * immutable |
| * locked |
| * writeonce |
| * readonly |
| </doodle> |
| |
===== References ===== | ===== References ===== |
Prior RFC proposing ''immutable'' properties: https://wiki.php.net/rfc/immutability | Prior RFC proposing ''immutable'' properties: https://wiki.php.net/rfc/immutability |
| |