Skip to content

[DependencyInjection] Fix proxying services defined with an abstract class and a factory #61121

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

Merged
merged 1 commit into from
Jul 15, 2025

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #61095
License MIT

@stof
Copy link
Member

stof commented Jul 15, 2025

how does this work for abstract classes that don't have only abstract methods or that have mandatory constructor arguments ?

@nicolas-grekas
Copy link
Member Author

how does this work for abstract classes that don't have only abstract methods or that have mandatory constructor arguments ?

Methods, whether abstract or not, are forwarded to the instance returned by the lazy-factory. Then, it's the job of the lazy-factory to do whatever is needed to create such instances.

@stof
Copy link
Member

stof commented Jul 15, 2025

@nicolas-grekas does it handle the case of a constructor with required arguments properly ? and what happens for final methods ?

@nicolas-grekas
Copy link
Member Author

For constructors: not our job. The service definition has to be correct.
Final methods on abstract classes will throw an exception saying this is not compatible.

@stof
Copy link
Member

stof commented Jul 15, 2025

@nicolas-grekas the service definition won't provide constructor arguments for the proxy instance, only for the actual instance.
So we should probably detect the case where the abstract class has a constructor to throw as unsupported (maybe first trying to override it and throwing only if not possible)

@nicolas-grekas
Copy link
Member Author

Ah sorry I misunderstood your question. We don't call the constructor, see newInstanceWithoutConstructor here:
https://github.com/symfony/symfony/blob/7.4/src/Symfony/Component/VarExporter/Internal/LazyDecoratorTrait.php

@nicolas-grekas nicolas-grekas merged commit af5a185 into symfony:7.3 Jul 15, 2025
10 of 11 checks passed
@nicolas-grekas nicolas-grekas deleted the di-lazy-if branch July 15, 2025 10:01
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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy