Skip to content

[Bridge\ProxyManager] Dont call __destruct() on non-instantiated services #23729

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
Aug 3, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jul 31, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23813
License MIT
Doc PR -

While working on making #23678 green, I discovered that if a lazy service implements __destruct, then that service is not lazy anymore: it is created at destruct time.
That behavior is documented at Ocramius/ProxyManager#258 (+related issues).

While I may understand why this behavior is the default for ProxyManager, it does not fit our "lazy-services" use case to me. Typically, nobody wants a database connection to be created to destruct the uninitialized lazy-proxy.

Blocks #23678

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jul 31, 2017
@nicolas-grekas nicolas-grekas force-pushed the proxy-lazy-destruct branch 3 times, most recently from c366fc7 to 6fb67d5 Compare July 31, 2017 13:32
@nicolas-grekas nicolas-grekas changed the title [Bridge\ProxyManager] Dont call __destruct() on non-instanciated services [Bridge\ProxyManager] Dont call __destruct() on non-instantiated services Jul 31, 2017
/**
* {@inheritdoc}
*/
protected function getGenerator() : ProxyGeneratorInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

You can't use feature from PHP 7 on branch that supports version 5.5

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@nicolas-grekas nicolas-grekas force-pushed the proxy-lazy-destruct branch 8 times, most recently from 6baa81f to b98fc0a Compare July 31, 2017 15:03
*/
class LazyLoadingValueHolderFactoryV1 extends BaseFactory
{
private $generatorV1;
Copy link
Member

Choose a reason for hiding this comment

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

why does it have a different name here ? Except for the property name, the code is the same in v1 and V2.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Aug 1, 2017

Choose a reason for hiding this comment

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

Because in v0.4, the property exists and is protected, thus can't be made private...

Copy link
Member

Choose a reason for hiding this comment

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

we could just use a name available in both versions

@fabpot
Copy link
Member

fabpot commented Aug 3, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 2d79ffa into symfony:2.7 Aug 3, 2017
fabpot added a commit that referenced this pull request Aug 3, 2017
…tiated services (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

[Bridge\ProxyManager] Dont call __destruct() on non-instantiated services

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

While working on making #23678 green, I discovered that if a lazy service implements `__destruct`, then that service is not lazy anymore: it is created at destruct time.
That behavior is documented at Ocramius/ProxyManager#258 (+related issues).

While I may understand why this behavior is the default for ProxyManager, it does not fit our "lazy-services" use case to me. Typically, nobody wants a database connection to be created to destruct the uninitialized lazy-proxy.

Blocks #23678

Commits
-------

2d79ffa [Bridge\ProxyManager] Dont call __destruct() on non-instantiated services
@nicolas-grekas nicolas-grekas deleted the proxy-lazy-destruct branch August 5, 2017 21:04
This was referenced Aug 28, 2017
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.

5 participants