Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

BusterNeece
Copy link
Contributor

@BusterNeece BusterNeece commented Jul 21, 2025

PHP 8.4 introduced support for language-native lazy proxy creation, and as a result, Ocramius's ProxyManager is deprecated for users of PHP 8.4 and above in favor of these native lazy proxies.

This PR adds an option to the ContainerBuilder called useNativeLazyObjects. The naming convention is taken from the Doctrine ORM's migration to native PHP lazy objects.

The existing Ocramius ProxyFactory is still intact and unchanged for users opting not to use the new functionality. Its class has been incorporated into a ProxyFactoryInterface that exposes common methods between it and the new NativeProxyFactory class. As some portions of the callable that was sent to the ProxyFactory were specific to Ocramius' proxy manager, these portions have been pulled up to that specific class in favor of a generic object builder callable that works with both services.

New integration and unit tests have also been created to ensure the functionality of the new code.

The only BC break expected from this change is that the Container class now expects a ProxyFactoryInterface instead of ProxyFactory itself, which will affect any custom wrapping container classes. Otherwise, no other BC breaks are expected.

Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

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

Thank you for working on this, this is awesome!

Can you confirm that if I'm on PHP 8.4 and I use lazy loading, then it's going to use the native proxies automatically?

Could you update https://github.com/PHP-DI/PHP-DI/blob/master/doc/lazy-injection.md as well? (no need for a full rewrite, just making sure it's correct).

@BusterNeece
Copy link
Contributor Author

Looks like if I switch the logic so that anyone on 8.4 or newer uses native proxies, then that breaks a fair number of the tests because they're expecting the specific return type and signature of the Ocramius implementation. I'll work on getting those tests updated. May be a little more work than expected if we go that route.

@BusterNeece
Copy link
Contributor Author

I updated the code to automatically enable native lazy objects for anyone using PHP 8.4 or newer, and I've updated the tests and docs accordingly.

@BusterNeece
Copy link
Contributor Author

Looks like the last thing keeping it from being all green is that minor phpdoc positioning thing in a file I didn't modify (well, I did but I reverted it).

@mnapoli
Copy link
Member

mnapoli commented Jul 22, 2025

ah I see, nevermind about that then (CS rule changes is annoying 😢), I need to take some time to review 👍

@mnapoli
Copy link
Member

mnapoli commented Aug 15, 2025

Thank you!

@mnapoli mnapoli merged commit 0543ee1 into PHP-DI:master Aug 15, 2025
7 of 8 checks passed
@vhd vhd mentioned this pull request Aug 15, 2025
mnapoli added a commit that referenced this pull request Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants