Closed forrest79 closed 11 months ago
This is correct, because BetterReflection would have to instantiate the object, therefore loading it.
BTW, the exception message is obviously confusing:
Could not locate constant TestEnum::X while trying to evaluate constant expression in method TestClass::test() in file
We could improve that :thinking:
Thanks for a rapid response. I solved this using getDefaultValueExpression
(my bad :-()
@forrest79 are we OK with just raising a better exception message here?
Absolutely :-) It was my fault, I was expecting, that Enum could be simply returned as a returned value.
@forrest79 are we OK with just raising a better exception message here? Would you be able to help with that, perhaps?
Yes, I will be glad to help. My idea is just to detect, if the class is an Enum and throw a different exception?
I'd say so, yep 👍
PR #1380
Handled in #1380
Hi, I figured out, that reflecting a class like this will fail on getting the default value for the
$x
parameter:I have got
Uncaught Roave\BetterReflection\NodeCompiler\Exception\UnableToCompileNode: Could not locate constant TestEnum::X while trying to evaluate constant expression in method TestClass::test() in file ...
.As a quick workaround, I added something like this:
Into
src/NodeCompiler/CompileNodeToValue.php
methodgetClassConstantValue()
. I wanted to return the correct enum instance, but I got another error, the enum is not supported as return value.