Skip to content
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

Add support for PHP 8.4 Lazy Objects RFC with configuration flag #11853

Merged
merged 21 commits into from
Mar 29, 2025

Conversation

beberlei
Copy link
Member

@beberlei beberlei commented Feb 27, 2025

Our goal is that we can completely replace all kinds of code for proxy generation and proxy usage with the new lazy objects feature of PHP 8.4: https://wiki.php.net/rfc/lazy-objects

In 3.4.x we can add support for optionally using lazy objects, and in 4.x we increase the requirement for PHP to 8.4 and automatically always use lazy objects.

The benefit of lazy objects is that we don't need code-generation anymore, and that it also allows us to treat partial objects as lazy objects that can load their missing properties only when accessed.

See #11659 for prerequisites of using new Reflection APIs.

Use:

$config = new \Doctrine\ORM\Configuration();
$config->enableNativeLazyObjects(true);

To run tests with this ENABLE_NATIVE_LAZY_OBJECTS=1 php vendor/bin/phpunit.

@beberlei beberlei changed the title Reflection lazy ghost 3.4.x Add support for PHP 8.4 Lazy Objects RFC with configuration flag Feb 27, 2025
… expensive and could lead to errors. Adjust lifecycle test that uses transient properittes for assertions.
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Well done!

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Well done, so happy it works this seamlessly :)
I agree with @GromNaN : the term proxy is now inaccurate; this uses the ghost strategy, no proxy is involved.

@beberlei beberlei requested a review from greg0ire February 28, 2025 20:44
…t required anymore with native lazy objects.
@greg0ire
Copy link
Member

greg0ire commented Mar 8, 2025

@jaapio the docs build suddenly fails, what should we do?

@jaapio
Copy link

jaapio commented Mar 8, 2025

You need to update phpDocumentor/filesystem. As this is an unexpected breaking change. But it's fixed when you update the package.

@greg0ire
Copy link
Member

greg0ire commented Mar 8, 2025

I made doctrine/.github#60 from my phone 📱

@greg0ire
Copy link
Member

A rebase should fix the build.

@@ -71,9 +76,26 @@ Configuration Options
The following sections describe all the configuration options
available on a ``Doctrine\ORM\Configuration`` instance.

Native Lazy Objects (***OPTIONAL***)
Copy link
Member

@greg0ire greg0ire Mar 24, 2025

Choose a reason for hiding this comment

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

The triple stars are bizarre and render bizarrely, I'm going to file a PR against 2.x to fix that.

EDIT: #11885

@greg0ire greg0ire mentioned this pull request Mar 24, 2025
@greg0ire
Copy link
Member

The build should be fixed with #11884

greg0ire
greg0ire previously approved these changes Mar 24, 2025
Comment on lines 93 to 97
Proxy Directory (***REQUIRED***)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This setting is not required if you use native lazy objects with PHP 8.4
and will be removed in the future.
Copy link
Member

Choose a reason for hiding this comment

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

Proposition if you remove the REQUIRED from the title.

Suggested change
Proxy Directory (***REQUIRED***)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This setting is not required if you use native lazy objects with PHP 8.4
and will be removed in the future.
Proxy Directory
~~~~~~~~~~~~~~~
Required except if you use native lazy objects with PHP 8.4.
This setting will be removed in the future.

@Rixafy
Copy link

Rixafy commented Mar 25, 2025

Nice job, btw, is the 3.4 release somewhat dependent on merging of this PR? Because I have also PR that I want to be in 3.4 as optional and 4.0 as default #11814 (php nullability inheritance) but it didn't get a review in 2 months, so I'm wondering if someone could take a look so it can also get to next version.

//edit: @greg0ire thanks for review!

@beberlei beberlei merged commit eb3b984 into doctrine:3.4.x Mar 29, 2025
86 checks passed
@beberlei beberlei mentioned this pull request Mar 29, 2025
7 tasks
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Mar 31, 2025
… < 8.4 (xabbuh)

This PR was merged into the 6.4 branch.

Discussion
----------

[DoctrineBridge] fix tests with Doctrine ORM 3.4+ on PHP < 8.4

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

The solution implemented in #59887 does no longer work on PHP < 8.4 with the changes made in doctrine/orm#11853.

Commits
-------

9be0d0a fix tests with Doctrine ORM 3.4+ on PHP < 8.4
nicolas-grekas added a commit to symfony/symfony that referenced this pull request Mar 31, 2025
This PR was merged into the 7.3 branch.

Discussion
----------

[DoctrineBridge] Adjust non-legacy tests

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

These should be unneeded since doctrine/orm#11853

Commits
-------

682f453 [DoctrineBridge] Adjust non-legacy tests
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.

7 participants