Comments (8)
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 self::DEFAULT_VALUE
is unknown at the time. This is unfortunate from a language design perspective, because what exactly can be evaluated during compilation and what can't is essentially an implementation detail (and may depend on whether opcache is used or not).
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.
from php-src.
@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.
from php-src.
It seems I didn't fully understood compile-time semantics, can be closed.
from php-src.
Not so fast; https://3v4l.org/5sZes works.
from php-src.
Found another interesting feature-bug:
class Example
{
final public const TEST = 42;
}
enum ExampleEnum: int
{
case CASE = Example::TEST;
}
- If you run the code for the first time, then it works
- If you run the code again (PHP 8.1.4), an error occurs:
Enum case value must be compile-time evaluatable
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.
PHP 8.1.4 (cli) (built: Apr 4 2022 13:30:33) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.4, Copyright (c) Zend Technologies
with Zend OPcache v8.1.4, Copyright (c), by Zend Technologies
Does it make sense to try to reproduce the behavior in other versions of the language (8.1.3, 8.1.2, etc)?
from php-src.
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?
from php-src.
@SerafimArts Feel free to create a new issue.
from php-src.
@iluuu1994 Yes, I'm sorry, that's probably how it should have been done initially, so as not to confuse different situations.
from php-src.
Related Issues (20)
- [ HELP REQUEST ] Continue already running generator to implement middleware flow HOT 1
- Test failures on Alpinelinux using OpenSSL 3.2+ HOT 3
- PHP-FPM `ping.path` and `ping.response` config vars are ignored. HOT 2
- php_curl does not work with IIS extended protection HOT 1
- is_float(integer) == true HOT 3
- Memory leak in xml extension HOT 3
- Opcache JIT segmentation fault HOT 3
- Update compilation parameters for the intl plugin HOT 6
- Segmentation fault libpq.so - freePGconn HOT 2
- Memory leaks when opcache preloading non-exist file HOT 1
- [Chore] resolve "perpetually open" CVEs for PHP and FPM HOT 7
- Unable to load dynamic library 'mysqli' HOT 7
- `make test` Privacy Issues HOT 3
- Reflection: promoted constructor parameter has no default value HOT 2
- ZEND_MOD_CONFLICTS doesn't work
- Scalar Type Casting Magic Methods HOT 2
- openssl_dh_compute_key() silently fails for ECDH HOT 2
- Signed Integer Overflow in ext/date/lib/parse_posix.c
- Segmentation fault on unknown address 0x600000000018 in ext/opcache/jit/zend_jit.c HOT 2
- Heap hardening HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-src.