Skip to content

Conversation

@yoeunes
Copy link
Contributor

@yoeunes yoeunes commented Nov 4, 2025

Q A
Branch? 7.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Issues Fixes #62291
License MIT

This PR fixes a bug where autowiring a lazy dependency for an interface (e.g., #[Autowire(lazy: true)] TestInterface) would fail if that interface was aliased to a final class.

The AutowirePass was attempting to resolve the alias to the concrete final class, which causes a fatal error on PHP < 8.4 as final classes cannot be proxied.

This fix updates the logic to:

  1. Always resolve aliases to concrete classes when possible (for non-final classes).
  2. Only on PHP < 8.4, if the resolved class is final, fall back to proxying the original type-hint (the interface) to avoid the fatal error.

Tests have been updated to cover these scenarios and now pass on all PHP versions without restrictions.

@yoeunes yoeunes force-pushed the di-lazy-proxy-final-class-7.3 branch from 18542bd to 2151173 Compare November 4, 2025 17:53
@yoeunes
Copy link
Contributor Author

yoeunes commented Nov 4, 2025

Hi @stof, thanks for the review!

I've updated the PR to always resolve aliases for lazy proxies when possible, but fallback to the original type (e.g., interface) for final classes on PHP < 8.4 to avoid proxy errors.

Tests now pass on PHP 8.2 and 8.4 without restrictions. (cc @nicolas-grekas)

@yoeunes yoeunes force-pushed the di-lazy-proxy-final-class-7.3 branch 6 times, most recently from ef0cdca to 58e136a Compare November 6, 2025 02:32
@yoeunes
Copy link
Contributor Author

yoeunes commented Nov 6, 2025

I've just pushed an update to refactor the logic to simplify the processValue method by extracting the proxy resolution into resolveProxyType. It should be cleaner and ready for review now.

@yoeunes yoeunes force-pushed the di-lazy-proxy-final-class-7.3 branch from 58e136a to 27daa84 Compare November 12, 2025 15:34
@nicolas-grekas nicolas-grekas force-pushed the di-lazy-proxy-final-class-7.3 branch from 27daa84 to 3dcc31b Compare November 12, 2025 17:46
@nicolas-grekas
Copy link
Member

Thank you @yoeunes.

@nicolas-grekas nicolas-grekas merged commit da55ca9 into symfony:7.3 Nov 12, 2025
9 of 11 checks passed
This was referenced Nov 13, 2025
@fabpot fabpot mentioned this pull request Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants