-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarExporter] Fix exporting default values involving global constants #56488
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
[VarExporter] Fix exporting default values involving global constants #56488
Conversation
2cad659
to
fbaed3b
Compare
ddf9e3b
to
4060c04
Compare
src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
Outdated
Show resolved
Hide resolved
e98b45a
to
ab96ab0
Compare
AFAIU looking at the current state of tests https://github.com/symfony/symfony/tree/5.4 it sounds like failures here are not related to the current change. |
Hi thanks for the PR. I'm surprised this change is in VarDumper and not in VarExporter. Does this really fix the issue you have? |
I guess both should be consistent and support what PHP natively support. For my use case, I'm looking for what is generating proxy-classes.php. |
Basically, I think Symfony may need to use this logic anywhere it's calling |
@nicolas-grekas You're right. It's not only applying to When having in the constructor of a service: __construct(
#[Autowire(lazy: true)]
private Foo $foo,
) And namespace Bar;
class Foo
{
public function byPi(float $number, float $pi = M_PI): float
{
return $number * $pi;
}
} Then casting to string the
And then using this string, Symfony will assume Is it enough so you see what issue we face or still want me to provide a mini-repo? I will try to make a PR to handle consistently both |
ab96ab0
to
4ac2ccb
Compare
4ac2ccb
to
4420c35
Compare
4420c35
to
3294b80
Compare
Updated the PR to handle only the case of A next (but independent) step could be #56824 so global constants can be resolved without the |
cf25382
to
7800cf6
Compare
7800cf6
to
5d33407
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the implementation to handle more cases (eg. when consts are nested in an array)
Thank you @kylekatarnls. |
Thank to you for the quick review and improvements here 🙏 |
This PR was merged into the 6.4 branch. Discussion ---------- [VarExporter] Fix test expectation | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Fixes a wrong expectation introduced in #56488 Commits ------- 19d573a [VarExporter] Fix test expectation
Hello, we hit a case when a service works fine when injected normally but stop working when injected lazily. The reason was that the default value of a parameter was a global constant that was used without explicitly specifying
\
nor importing it. It ends up being incorrectly transformer in the proxy class as\MyNamespace\GLOBAL_CONSTANT
instead of\GLOBAL_CONSTANT
.We worked around that by adding the
\
in this service which is anyway rather a good move to be explicit. However I believe theReflectionCaster
should support this case because: