I have read plenty of C# examples of Value Objects, and I understand that it is an “object” that is identified by it’s values. If a value changes, the object is “new”.
However, that doesn’t seem to make sense when it comes to PHP…either that, or I’m just not making the connection.
Is a Value Object just a string?
To put this into context, in many OO languages, objects are compared by their identity. In pseudocode:
Even though both objects are basically the same if you just look at their values, they’re not considered to be identical, because they are separate instances. To demonstrate:
Now:
This would be a demonstration of "value objects":
Because the values are the same, both objects are considered equal, even if they’re separate instances.
PHP does not have a separate concept of "value objects", it only has one type of object. Its comparison operator can make that distinction though:
E.g.: