You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I got to a project that uses these enums and I found out that they cannot be natively compared with each other. To be sure, I compared all combinations of createable instances against each other.
finalclass Foo extendsBenSampo\Enum\Enum
{
publicconstBAR = 0;
}
$factories = [
'__construct' => function () { returnnewFoo(Foo::BAR); },
'fromValue' => function () { return Foo::fromValue(0); },
'fromKey' => function () { return Foo::fromKey('BAR'); },
'__callStatic' => function () { return Foo::BAR(); },
'coerce#value' => function () { return Foo::coerce(0); },
'coerce#key' => function () { return Foo::coerce('BAR'); },
];
foreach ($factoriesas$ad => $af) {
$a = $af();
if ($ainstanceof Foo) {
foreach ($factoriesas$bd => $bf) {
$b = $bf();
if ($binstanceof Foo && $a !== $b) echo"{$ad} is not same as {$bd}\n";
}
} elseecho"{$ad} is not instance of Foo\n";
}
__construct is not same as __construct
__construct is not same as fromValue
__construct is not same as fromKey
__construct is not same as __callStatic
__construct is not same as coerce#value
__construct is not same as coerce#key
fromValue is not same as __construct
fromValue is not same as fromValue
fromValue is not same as fromKey
fromValue is not same as __callStatic
fromValue is not same as coerce#value
fromValue is not same as coerce#key
fromKey is not same as __construct
fromKey is not same as fromValue
fromKey is not same as fromKey
fromKey is not same as __callStatic
fromKey is not same as coerce#value
fromKey is not same as coerce#key
__callStatic is not same as __construct
__callStatic is not same as fromValue
__callStatic is not same as fromKey
__callStatic is not same as __callStatic
__callStatic is not same as coerce#value
__callStatic is not same as coerce#key
coerce#value is not same as __construct
coerce#value is not same as fromValue
coerce#value is not same as fromKey
coerce#value is not same as __callStatic
coerce#value is not same as coerce#value
coerce#value is not same as coerce#key
coerce#key is not same as __construct
coerce#key is not same as fromValue
coerce#key is not same as fromKey
coerce#key is not same as __callStatic
coerce#key is not same as coerce#value
coerce#key is not same as coerce#key
Even instances created in the same way are not same.
I don't quite understand the point of an enum whose members cannot be compared (matched, switched,...), so please add a big warning about this strange behavior at the beginning of README.md.
The text was updated successfully, but these errors were encountered:
I documented this behaviour in #344. It probably would have been best to use singletons when instantiating enums, but introducing that now would be a massive breaking change. Given this library is in maintenance mode - see #332 - it will not change this anymore.
Hi,
I got to a project that uses these enums and I found out that they cannot be natively compared with each other. To be sure, I compared all combinations of createable instances against each other.
Even instances created in the same way are not same.
I don't quite understand the point of an enum whose members cannot be compared (matched, switched,...), so please add a big warning about this strange behavior at the beginning of
README.md
.The text was updated successfully, but these errors were encountered: