rfc:immutability

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
rfc:immutability [2018/02/18 23:33] marijic.silviorfc:immutability [2018/02/20 11:19] (current) marijic.silvio
Line 4: Line 4:
   * Author: Michal Brzuchalski <michal@brzuchalski.com>   * Author: Michal Brzuchalski <michal@brzuchalski.com>
   * Author: Silvio Marijic <marijic.silvio@gmail.com>   * Author: Silvio Marijic <marijic.silvio@gmail.com>
-  * Status: In Draft+  * Status: In Discussion
   * First Published at: [[rfc:immutability|https://wiki.php.net/rfc/immutability]]   * First Published at: [[rfc:immutability|https://wiki.php.net/rfc/immutability]]
  
Line 22: Line 22:
  
 **Cons** **Cons**
-  - (Please point it out more disadvantages)+  - Currently arrays on immutable properties are not supported.
  
  
Line 84: Line 84:
 </code> </code>
  
-Resources are not allowed to be assigned to immutable properties because of fact that resourcesby natureare 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 107: Line 107:
 } }
  
-$file = new A(['foo']);+$= new A(['foo']);
 </code> </code>
  
Line 134: Line 134:
 </code> </code>
  
 +==== 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->email = $email;
 +  }
 +}
 +
 +$email1 = new Email("foo@php.net");
 +$email2 = new Email("foo@php.net");
 +var_dump($email1 === $email2); // bool(true)
 +</code>
  
 ===== Examples ===== ===== Examples =====
Line 289: Line 308:
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
  
- - PHP 7.2+ To be discussed.
  
 ===== RFC Impact ===== ===== RFC Impact =====
Line 320: 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 327: Line 348:
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
-[[https://github.com/php/php-src/compare/master...brzuchal:immutable]]+[[https://github.com/php/php-src/compare/master...smarijic:immutable-rfc]]
  
  
rfc/immutability.1518996818.txt.gz · Last modified: 2018/02/18 23:33 by marijic.silvio