-
-
Notifications
You must be signed in to change notification settings - Fork 132
Fix for search() is not type safe. Fixes #13 #14
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
Conversation
Sorry for the delay :) |
Fix for search() is not type safe. Fixes #13
This actually brought backward incompatibilities. If you have a enum that contains constant X = 1; It was possible to use '1' (string) in place of 1 (integer) for instantiating it. |
Ok, it was considered a bug. It's good that this is fixed so it is caught during development now and not later. |
@drealecs yeah, I totally get your point :) According to semver, version number
|
Hey guys, sorry for the late response I was on holidays without internet access. I indeed considered this a bug so in theory the patch release makes sense, but I definitely agree that I should have been more careful with that (somehow), so my apologies :/ Do you see any way we could have non-strict comparison work for values that make sense? E.g. |
@mnapoli as the case of matching values you describe differs from how php treats truthy and falsy values (and casting between them), the only way it could work is with custom mapping ('1' matches 1 etc.). The problem with any mapping, however, is that there can always be a case that seems to make sense for library user. If you intend to add Consts values, by design, should work as unique identifiers of enum. The problem is that it's clumsy for base As the bugfix is already released, you can have two groups of users: ones that already rely on hard typing and the ones, like @drealecs, who are affected by it. Having considered both, I think having "hard typing" still saves users from many more fuckups. BTW. We could, in theory, use Reflection at |
Yeah I agree with you it's not inline with PHP's behavior (it would be a mix in-between weak and strict comparison), so not really possible. I definitely like strict too, the only thing I'm wary of is imagine that (simplified) situation: class State extends Enum
{
const OPEN = 1;
}
$value = new State($_GET['state']);
But I guess it's easy both to understand the problem (the exception will be explicit) and to fix it… So we should probably not try to cover those use cases and stay strict. |
@mnapoli please have a look