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
Type coercion? #35
Comments
When else besides cases() would the primitive be used then? Having a primitive that you can never actually leverage except in |
Well, you still need a way to explicitly get the value. We'd need that for strict types anyway. And I've just realized that behavior isn't even described. We'd need something like |
@Crell So, what do you think? IMO |
My main concern is what is going to make life easiest for people round tripping enum data to the database. I'm comfortable with whatever they're comfortable with. |
I think if we do want type coercion we need it both ways (convert strings/ints back to the enum). I have not investigated how easy this is. What could also cause some headaches is something like this: enum Foo: int {
case Bar = 42;
}
takesString(Foo::Bar); // Do we convert to int and then string? Type error?
I'm ready to investigate this for a few hours if you feel coercion is important. |
Let's see if we can get feedback from the ORM and DBAL people first to see what would be optimal for them, then we can see how easily we can achieve that. No sense trying to make something work they don't actually want. |
Comment from Nikita on the topic:
|
Additionally, if we ever chose to add enumset, |
@Crell Your thoughts? |
I need two things, a property or method to convert the enum into a scalar value, and a factory method to create an enum instance from the scalar value. enum MyEnum {
// ...
}
$value = $enum->value;
$enum = MyEnum::create($value); |
@beberlei The RFC should meet these requirements even after removing type coercion (except that we call |
@Crell Can you share your thoughts? Arguments for type coercion:
Arguments against type coercion:
|
I don't have a strong feeling about it either way, to be honest, beyond what ends up most ergonomic for cases that will be converting back and forth a lot. That's mainly DBALs and template engines. If the DBAL and template engine people don't have a strong case for auto-conversion, then I'm fine with leaving that out. The only reason to include it, IMO, would be if it makes their lives considerably easier. |
Cool, then let's drop it 🙂 |
Dropped, and moved to Future Scope as something for a future PHP to possibly reintroduce after we have more experience in the wild. |
Do we really need type coercion? Especially since the RFC currently only allows one-sided coercion (from objects to scalars) I'd be happier dropping it altogether.
The text was updated successfully, but these errors were encountered: