What is an example Value object in PHP?

I have read many examples of C # Value objects, and I understand that this is an “object” that is identified by its values. If the value changes, the object is "new."

However, that doesn't make sense when it comes to PHP ... either that, or I just don't make the connection.

Is a Value object just a string?

+5
source share
2 answers

To put this in context, in many OO languages ​​objects are compared by their identity. In pseudo code:

bar = new Foo
baz = new Foo

bar == baz  // false

Although both objects are basically the same, if you just look at their meanings, they are not considered identical because they are separate instances. To demonstrate:

bar = new Foo
baz = bar

bar == baz  // true

Now:

, , .

http://en.wikipedia.org/wiki/Value_object

" ":

address1 = new Address('Main street 42')
address2 = new Address('Main street 42')

address1 == address2  // true

, , .

PHP " ", . :

(==) , : , .

http://www.php.net/manual/en/language.oop5.object-comparison.php

:.

$address1 = new Address('Main street 42');
$address2 = new Address('Main street 42');

$address1 == $address2;  // true     equal...
$address1 === $address2;  // false   ...but not identical
+17

PHP , PHP4. . http://3v4l.org/ghI8G

0

All Articles