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 "skipDestructor" option to lazy loading proxies #641

Closed
wants to merge 1 commit into from
Closed

Add "skipDestructor" option to lazy loading proxies #641

wants to merge 1 commit into from

Conversation

nicolas-grekas
Copy link
Contributor

This PR adds a new skipDestructor option to lazy proxies (ghosts and value holders) that skips calling the original destructor when the object is not initialized.

This is something that is much needed in DI containers, where e.g. we don't want opening a database connection on an unused Doctrine object.

For the record, Symfony already has a similar check in place, but it is implemented using monkey-patching. Because of the policies in place here (new features are available only on the very latest PHP version), I had absolutely no incentive in contributing here since I couldn't actually use that work anytime soon.

Now that I decided to maintain a fork of this code, I know that anything I contribute here could be used in the short term. That's a great incentive.

The good news is that you don't have to change your policies. OSS dynamics FTW here also.

@nicolas-grekas
Copy link
Contributor Author

About the mutation score, I tried the mutants locally, they all fail when applied. I don't know what is missing, please advise.

Copy link

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Nitpicking so @Ocramius doesn't need to point it out, but in favour of the change 👍

$excludedMethods = ProxiedMethodsFilter::DEFAULT_EXCLUDED;

if ($skipDestructor) {
$excludedMethods[] = '__destruct';
Copy link

Choose a reason for hiding this comment

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

Nit: rename the option to "excludeDestructor" since that seems to be the internal wording.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this proposal: "exclude" here is used for a different thing.

Copy link

Choose a reason for hiding this comment

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

My thinking was that you're excluding the destructor from the list of proxied methods, but I defer to your (and @Ocramius') judgment on this 👍

@Ocramius
Copy link
Owner

Potentially, this could also be a solution to #468 and #373, and giving the end user the foot-gun seems like a sensible choice.

Patch makes sense, although I do need to take more time to review.

Be aware that this will only land in a new minor release, which may end up being ~8.0.0, or perhaps I do a new minor with just this, then one with ~8.0.0 if it helps.

@Ocramius Ocramius added this to the 2.11.0 milestone Dec 20, 2020
@Ocramius Ocramius self-assigned this Dec 20, 2020
@Ocramius Ocramius modified the milestones: 2.11.0, 2.12.0 Dec 30, 2020
@Ocramius
Copy link
Owner

No time to get it in 2.11.0, hence moving it to 2.12.0

@nicolas-grekas nicolas-grekas changed the base branch from 2.11.x to 2.12.x January 3, 2021 17:15
@nicolas-grekas
Copy link
Contributor Author

nicolas-grekas commented Jan 3, 2021

Rebased, let me know the next iteration.

@Ocramius Ocramius modified the milestones: 2.12.0, 2.13.0 May 25, 2021
@Ocramius Ocramius modified the milestones: 2.13.0, 2.14.0 Jun 9, 2021
@Ocramius Ocramius modified the milestones: 2.14.0, 2.15.0 Feb 28, 2022
@Ocramius Ocramius changed the base branch from 2.12.x to 2.15.x February 28, 2022 13:59
@nicolas-grekas nicolas-grekas closed this by deleting the head repository May 17, 2023
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