-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Can't use inherited constant value via 'self' in enum case value #7821
Comments
It seems I didn't fully understood compile-time semantics, can be closed. |
Not so fast; https://3v4l.org/5sZes works. |
The problem here is that we compute a value to case table during compilation and all values must be known at that time. This happens pre-inheritance, so I think it should be possible to make this part of inheritance instead, which should allow us to evaluate all expressions. It would also delay some error reporting (about duplicate case values) to that point. |
Found another interesting feature-bug: class Example
{
final public const TEST = 42;
}
enum ExampleEnum: int
{
case CASE = Example::TEST;
}
There is a suspicion that this is somehow related to opcache: $ php test.php -dopcache.jit_buffer_size=0 -dopcache.enable=1 -dopcache.enable_cli=0
// - First execution 42
// - Second execution 42
// - Third execution 42
$ php test.php -dopcache.jit_buffer_size=0 -dopcache.enable=1 -dopcache.enable_cli=1
// - First execution 42
// - Second execution: Enum case value must be compile-time evaluatable
// - Third execution: Enum case value must be compile-time evaluatable P.S.
Does it make sense to try to reproduce the behavior in other versions of the language (8.1.3, 8.1.2, etc)? |
@SerafimArts Thanks! I think this should also be solved by #8190 but I'll make sure to add a test. You don't have to test it for older patches, not much has changed in the patches for enums. Edit: Although this qualifies as a bug. I'll see if I can fix that for 8.1. |
Yea. Let me move this information into a separate issue? |
@SerafimArts Feel free to create a new issue. |
@iluuu1994 Yes, I'm sorry, that's probably how it should have been done initially, so as not to confuse different situations. |
Closes phpGH-7821 Closes phpGH-8190 Closes phpGH-8418
Description
The following code:
Resulted in this output:
But I expected this output instead:
No errors, because commented
case GAMBRINUS = I::DEFAULT_VALUE
produces no errorPHP Version
8.1.1
Operating System
No response
The text was updated successfully, but these errors were encountered: