Skip to content

[DependencyInjection] Leverage native lazy objects for lazy services #59913

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
Mar 13, 2025

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? yes
Issues -
License MIT

When a service is lazy, we can leverage native lazy objects on PHP 8.4.

(Note that we still need var-exporter to generate lazy proxies when using the proxy tag - aka when proxying "by interface".)

if (!$manager instanceof LazyLoadingInterface) {
throw new \LogicException(\sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name));
}
trigger_deprecation('symfony/doctrine-bridge', '7.3', 'Support for proxy-manager is deprecated.');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case should never happen (who would use proxy-manager directly instead of Symfony's lazy services for the Doctrine EM!?), still added for completeness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this deprecation always triggered on PHP 8.3 and older ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's guarded by if (!$manager instanceof LazyLoadingInterface) { (note the !) so only when ppl use proxy-manager, which we don't anymore thanks to var-exporter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. This deprecation is triggered after that if, when we haven't thrown an exception (and so in the case where we will actually reset the object)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I missed that the case of lazy objects using var-exporter are handled before the check for PHP 8.4, so this is not the code path we reach in modern projects.

@nicolas-grekas nicolas-grekas merged commit 0c11d82 into symfony:7.3 Mar 13, 2025
8 of 11 checks passed
@nicolas-grekas nicolas-grekas deleted the di-native-lazy branch March 13, 2025 14:47
@rvanlaak
Copy link
Contributor

Nice! Could this PR possibly also improve performance? Any idea on how to benchmark that?

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