BUGFIX: Don't create proxy classes for PHP enums#2702
Conversation
This change introduces a check in the proxy class compiler which makes sure that PHP 8.1 enums are not considered as regular classes and are removed from the list of proxyable classes. Addresses neos#2698
albe
left a comment
There was a problem hiding this comment.
Looks good, thanks! Can we do something like we did here https://github.com/neos/flow-development-collection/blob/master/Neos.Flow/Classes/ObjectManagement/CompileTimeObjectManager.php#L231 => https://github.com/neos/flow-development-collection/tree/master/Neos.Flow/Tests/Functional/ObjectManagement/Fixtures/PHP8 and add such an enum to the tests conditionally for PHP81?
Yes, more or less – we can't check if the enum was proxied, because it never will be, since the compiler would fail with a fatal error. But yes, we need to back this with a test, so I just pushed one. |
|
Hmm. Now we need to find a good way to sneak this test in without breaking the < PHP 8.1 runs. |
1797c67 to
536fdaa
Compare
|
Okay, I think I found a solution an force-pushed the commit providing the functional test. |
|
Sadly it fails for PHP 8.0 with |
|
Oh and we should run tests for 8.1 I guess ;-) |
|
@8.1 tests: |
|
StyleCI doesn't seem to like enums … |
|
kitsunet
left a comment
There was a problem hiding this comment.
Looks good, thanks! Good to have that fixed
bwaidelich
left a comment
There was a problem hiding this comment.
I think this makes sense, but as written in Slack IMO we should strive towards creating proxies only if they are really needed. And, if a proxy was to be created for a class that is not supported (e.g. an enum) an exception should be thrown.
Otherwise: What happens if you add an AOP aspect for an enum with this change? Will it be ignored?
| if ($package instanceof FlowPackageInterface && $shouldRegisterFunctionalTestClasses) { | ||
| foreach ($package->getFunctionalTestsClassFiles() as $fullClassName => $path) { | ||
| if (PHP_MAJOR_VERSION < 8 && strpos($fullClassName, '\\PHP8\\') !== false) { | ||
| if (version_compare(PHP_VERSION, '8.0', '<=') && strpos($fullClassName, '\\PHP8\\') !== false) { |
There was a problem hiding this comment.
Not sure if it's much better, but my PHPStorm suggests to change this line to
| if (version_compare(PHP_VERSION, '8.0', '<=') && strpos($fullClassName, '\\PHP8\\') !== false) { | |
| if (PHP_VERSION_ID <= 80000 && strpos($fullClassName, '\\PHP8\\') !== false) { |
But apart from that: I'm wondering what these checks actually do?
Could we add some inline comment to explain that?
| /** | ||
| * A PHP 8.1 value-backed enum with methods | ||
| */ | ||
| enum BackedEnumWithMethod: string |
There was a problem hiding this comment.
I assume that this fixture is not loaded with PHP < 8.1 and doesn't cause any harm that way!?
There was a problem hiding this comment.
Yes, exactly what you wondered about in CompileTimeObjectManager.php
|
What do we do with the failing psalm and styleci tests? They are false-positives, correct? |
I'll take care… |
|
✅ |
|
Post-merge 👍 Thanks everyone! |

This change introduces a check in the proxy class compiler which makes sure that PHP 8.1 enums are not considered as regular classes and are removed from the list of proxyable classes.
How to reproduce:
Packages/Acme/Classes/ExampleEnum.php:Addresses #2698