rfc:immutability
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:immutability [2017/03/22 16:12] – Tidied up the grammar and spelling and altered pronouns to be gender neutral geeh | rfc:immutability [2018/02/20 11:19] (current) – marijic.silvio | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Immutable classes and properties ====== | ====== PHP RFC: Immutable classes and properties ====== | ||
- | * Version: 0.1 | + | * Version: 0.2 |
- | * Date: 2016-08-12 | + | * Date: 2018-02-19 |
* Author: Michal Brzuchalski < | * Author: Michal Brzuchalski < | ||
* Author: Silvio Marijic < | * Author: Silvio Marijic < | ||
- | * Status: In Draft | + | * Status: In Discussion |
* First Published at: [[rfc: | * First Published at: [[rfc: | ||
Line 22: | Line 22: | ||
**Cons** | **Cons** | ||
- | - (Please point it out more disadvantages) | + | - Currently arrays on immutable properties are not supported. |
Line 84: | Line 84: | ||
</ | </ | ||
- | Resources are not allowed to be assigned to immutable properties because of fact that resources, by nature, are not immutable. | + | Resources are not allowed to be assigned to immutable properties because of fact that resources by nature are not immutable. |
<code php> | <code php> | ||
class File { | class File { | ||
Line 95: | Line 95: | ||
$file = new File(fopen(' | $file = new File(fopen(' | ||
+ | </ | ||
+ | |||
+ | Arrays are not allowed to be assigned to immutable properties.. | ||
+ | <code php> | ||
+ | class A { | ||
+ | public immutable $x; | ||
+ | |||
+ | public function __construct ($x) { | ||
+ | $this->x = $x; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $a = new A([' | ||
</ | </ | ||
Line 121: | Line 134: | ||
</ | </ | ||
+ | ==== Comparison ==== | ||
+ | |||
+ | Identity of immutable object is based on its value. So two immutable are identical if they are of the same type and contain same value. | ||
+ | |||
+ | <code php> | ||
+ | immutable class Email { | ||
+ | public $email; | ||
+ | |||
+ | public function __construct ($email) { | ||
+ | // validation | ||
+ | |||
+ | $this-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | $email1 = new Email(" | ||
+ | $email2 = new Email(" | ||
+ | var_dump($email1 === $email2); // bool(true) | ||
+ | </ | ||
===== Examples ===== | ===== Examples ===== | ||
Line 276: | Line 308: | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | - PHP 7.2 | + | To be discussed. |
===== RFC Impact ===== | ===== RFC Impact ===== | ||
Line 307: | Line 339: | ||
===== Future Scope ===== | ===== Future Scope ===== | ||
+ | Add support for arrays on immutable properties. | ||
+ | Expand immutability to regular variables also. | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
Line 314: | Line 348: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | [[https:// | + | [[https:// |
rfc/immutability.1490199120.txt.gz · Last modified: 2017/09/22 13:28 (external edit)