June 2017
Intermediate to advanced
394 pages
8h 52m
English
As discussed at the beginning of the chapter, two Value Objects are equal if the content they measure, quantify, or describe is the same.
For example, imagine two Money objects representing 1 USD. Can we consider them equal? In the real world, are two bills of 1 USD valued the same? Of course they are. Directing our attention back to the code, the Value Objects in question refer to separate instances of Money. However, they both represent the same value, which makes them equal.
In regards to PHP, it's commonplace to compare two Value Objects using the == operator. Examining the PHP Documentation definition of the operator highlights an interesting behavior:
When using the comparison operator ==, object variables are compared ...