-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible error in EmailAddress #6
Comments
@Zolli In PHP instances of the same class can access their private properties. This is a feature of PHP, not a bug. So. <?php
class MyObject {
private $property = 'x';
public function equals(MyObject $object) {
// because $object and $this are of the same class (MyObject)
// the property can be accessed even though it is private
// this is because php only prohibits other *classes* - and thus not instances - to access private properties
return $this->property === $object->property;
}
} |
Oh, sorry about that. I dont use this feature very often. |
No problem. You might also have a look at the tests. This functionality is tested here. Otherwise, I might also recommend reading upon value objects, or specific for PHP. In this case So. $address1 = new EmailAddress('test@test.com');
$address2 = new EmailAddress('test@test.com');
$address3 = new EmailAddress('xxx@test.com');
$address1->equals($address2); // true
$address1->equals($address3); // false This is different from entities and models. For models and entities the equality is based on the id of the object. $user1 = new User(['id' => 1]);
$user2 = new User(['id' => 2]);
$user3 = new User(['id' => 3]);
$user1->equals($user2); // true
$user1->equals($user3); // false Hope it helps understanding the concept! It is really valuable (!) |
@frederikbosch, I understand the concept, only those private access from the same type behavior not. Thanks for write this down. This could be very useful. |
While I looking at the code I ran into the EmailAddress::equals() method. The method expect an EmailAddress as first parameter and use this to read the property called address ($address->address), but this property has private visibility. Probably submit a PR for that.
The text was updated successfully, but these errors were encountered: