Skip to Content
Domain-Driven Design in PHP
book

Domain-Driven Design in PHP

by Keyvan Akbary, Carlos Buenosvinos, Christian Soronellas
June 2017
Intermediate to advanced
394 pages
8h 52m
English
Packt Publishing
Content preview from Domain-Driven Design in PHP

Value Equality

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Web Services

PHP Web Services

Lorna Jane Mitchell
PHP Microservices

PHP Microservices

Pablo Solar Vilariño, Carlos Pérez Sánchez

Publisher Resources

ISBN: 9781787284944