-
Notifications
You must be signed in to change notification settings - Fork 7.9k
GH-16447: improve enums' error when missing interface's hooked properties #16448
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
base: PHP-8.4
Are you sure you want to change the base?
Conversation
…perties Enums cannot have properties, and so can not be made to satisfy the interface at all; show a clearer error message than the suggestion to implement the hooked properties.
Do we need this custom error? We have other, very similar cases for forbidden methods, e.g. https://3v4l.org/ChAkh |
Though that specific method (__toString) doesn't work because Enums cannot implement Stringable, if you had a different name https://3v4l.org/1cnsv
this is something that the developer can actually address. On the other hand, with a hooked property
This is impossible and the developer cannot actually do this. If I hadn't know it was impossible, I would definitely spend time trying to figure out how to do it, and then get annoyed when I learned that it was impossible and I had wasted time. |
Right, that's the point. Enums can't declare |
In that case, I can also send a patch for the magic methods to not have the misleading error message - I agree we shouldn't do one but not the other, but think its better to do both than neither |
I'm not sure it's a huge benefit. I would rather not litter random error messages into the codebase without a more coherent approach. Checking for these methods during implementation of interfaces will just repeat the same checks we already do. |
So you don't want the property messages to have a warning from the interface because it isn't consistent with the magic methods, and you also don't want to have a warning for magic methods in the interface? |
Bump - can you confirm if my understanding here is correct? If so I'll look into drafting a "more coherent approach" |
Optimally, we should have useful and logically consistent messages that don't require adding error messages in multiple places. That was my main concern: It's already hard to keep error messages consistent because they are littered all over the place, in a way that they can't easily be consolidated. I think we should improve that rather than making it worse. Maybe you can re-use zend_verify_enum() rather than replicating the same rules in a different place. |
Enums cannot have properties, and so can not be made to satisfy the interface at all; show a clearer error message than the suggestion to implement the hooked properties.