I just came across an interesting bug I thought you might like.
I have a Set that is being created using an array like this pseudo code
foreach ($users as &$userId) {
$userId = UserId::fromString($userId->user_uuid);
}
$result = new Set($users);
UserId implements Hashable.
When I come to add another UserId to the Set, even if the hash functions return the same value, and the equals functions return true, the new UserId is added to the Set.
Set after loop and before add:
class Ds\Set#41 (3) {
public ${0} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#40 (1) {
private $identity =>
string(36) "4f220a85-1b2f-40f6-91c8-5879a8331c9f"
}
public ${1} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#42 (1) {
private $identity =>
string(36) "5e006610-5ed4-4393-a6e7-57857ac5deec"
}
public ${2} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#43 (1) {
private $identity =>
string(36) "b6f23619-dfca-423f-b598-3878a30abbc1"
}
}
Set after loop and after add
class Ds\Set#41 (4) {
public ${0} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#40 (1) {
private $identity =>
string(36) "4f220a85-1b2f-40f6-91c8-5879a8331c9f"
}
public ${1} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#42 (1) {
private $identity =>
string(36) "5e006610-5ed4-4393-a6e7-57857ac5deec"
}
public ${2} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#43 (1) {
private $identity =>
string(36) "b6f23619-dfca-423f-b598-3878a30abbc1"
}
public ${3} =>
class ThoughtRiver\Review\Domain\Model\User\UserId#32 (1) {
private $identity =>
string(36) "5e006610-5ed4-4393-a6e7-57857ac5deec"
}
}
Notice indexes 1 and 3
If I change the loop to the following:
$result = new Set;
foreach ($users as $userId) {
$result->add(UserId::fromString($userId->user_uuid));
}
Then I cannot add a new UserId to the Set when the Set already contains an object that equals considers to be true.
How weird?
I just came across an interesting bug I thought you might like.
I have a
Setthat is being created using an array like this pseudo codeUserIdimplementsHashable.When I come to add another
UserIdto theSet, even if thehashfunctions return the same value, and theequalsfunctions returntrue, the newUserIdis added to theSet.Setafter loop and beforeadd:Setafter loop and afteraddNotice indexes 1 and 3
If I change the loop to the following:
Then I cannot add a new
UserIdto theSetwhen theSetalready contains an object thatequalsconsiders to betrue.How weird?