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

Skip to content

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Aug 5, 2025

(Builds on top of #1905 and only the second commit is relevant to this PR).

This will fully resolve #1895 by no longer enabling the deprecated proxy autoloader when native lazy objects are in use.

As well, the proxy cache warmer will no longer be registered when native lazy objects are in use as the warmer doesn't really have a use when proxies aren't in use and it errors out when not configuring the deprecated proxy options (see #1898 (comment) and follow-on comments for more here).

Lastly, some of the tests are updated to run with native lazy objects enabled where the environment supports it.

Closes #1895

mbabker added 2 commits August 5, 2025 09:56
…lazy objects, start running tests with native lazy objects enabled
throw new LogicException(
'Native lazy objects are not supported with your installed version of the ORM. Please upgrade to "doctrine/orm:^3.4".',
);
}
Copy link
Member

Choose a reason for hiding this comment

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

This is also missing a validation that PHP 8.4 is used, otherwise error because native lazy is not supported then. This would throw the error earlier than doctrine on configuration level, otherwise it would be delayed to runtime when ORM is used.

Choose a reason for hiding this comment

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

Why would one set enable_native_lazy_objects to true when they are not at PHP8.4?

Besides that: It checks whether the ORM config has the necessary method to handle the config-value.

I'd rather check that setting enable_native_lazy_object to true is only possible starting with PHP8.4. So even if someone sets it ti true but runs the code on 8.3 it should get set to false automatically.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it should be set to false silently. Maybe it's even possible to just not define the configuration node for PHP < 8.4

Copy link
Member

Choose a reason for hiding this comment

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

Making configuration classes conditional on the PHP version is a bad idea: it makes it a mess to document the structure of the configuration and provides non-friendly error messages to the user ("configuration setting enable_native_lazy_object does not exist.", while they will see it in the documentation).
Note also that making conditional configuration in Yaml files is not possible, so this will make it impossible to write a recipe for the bundle that turns on the feature.

Choose a reason for hiding this comment

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

Silently setting it to false (which is the same as just ignoring it) would allow people to configure it but it would not break when running on some not-supported system.

I can think of i.e. staging running on 8.4 but prod is still on 8.3 - silently setting it to false will allow one setting for both and it would run on both without issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Silently setting it to false (which is the same as just ignoring it) would allow people to configure it but it would not break when running on some not-supported system.

The option is already effectively no-op'ed for PHP 8.3 and earlier in https://github.com/doctrine/DoctrineBundle/pull/1906/files#diff-e2aeb4a501e79bc8ebab5ea93069b5bbcd3eb9168d37bd78ddd43075cddb8cc4R722 (the Configuration::enableNativeLazyObjects() method call is only made on PHP 8.4+). So the "silently setting to false" thing is already happening in the tagged 2.15 releases.

Copy link
Member

Choose a reason for hiding this comment

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

I can think of i.e. staging running on 8.4 but prod is still on 8.3

Is that something people actually do? Pushing the same code on 2 machines with different versions of PHP? It seems risky to me, for instance if you use a php 8.4-specific feature, this setup will cause an issue that surfaces only in production. Plus it's not like they could wait until production also uses 8.4 to enable native lazy objects.

Copy link
Member

Choose a reason for hiding this comment

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

the ORM throws an exception if you are < 8.4 and use this setting.

https://github.com/doctrine/orm/blob/3.5.x/src/Configuration.php#L668

So that is the behavior that exists and we should not "change" this behavior to be something different, because thats confusing. What we can do is surface this error earlier, which we can do by doing the check here again, moving this to a "compile time" error instead of waiting for it to happen for runtime.

Copy link
Contributor Author

@mbabker mbabker Aug 25, 2025

Choose a reason for hiding this comment

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

67754db adds a throw at compile time for this.

@erseco
Copy link

erseco commented Aug 24, 2025

Thanks for this! We’re running PHP 8.4 with ORM 3.4+ and switching to enable_native_lazy_objects: true. Happy to help test a 2.16.x release/RC.

@ostrolucky ostrolucky merged commit d0cad43 into doctrine:2.16.x Aug 27, 2025
13 checks passed
@mbabker mbabker deleted the proxy-autoloader branch August 27, 2025 11:38
@greg0ire greg0ire added this to the 2.16.0 milestone Sep 2, 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.

7 participants