rfc:immutability
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
rfc:immutability [2018/02/19 21:09] – marijic.silvio | rfc:immutability [2018/02/19 21:13] – marijic.silvio | ||
---|---|---|---|
Line 134: | 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 ===== |
rfc/immutability.txt · Last modified: 2018/02/20 11:19 by marijic.silvio