Skip to content

Lazy services should not have their desctructor proxied #202

@func0der

Description

@func0der

Feature Request

When you proxy a class that has a destructor in it, the proxy manager by default creates a proxy for the __destruct method.
Then without actually needing or using the class the destructor is called at the end of execution which loads the lazy loaded class.

There is a possibility to configure this behavior in the proxy manager by passing $proxyOptions['skipDestructor'], but there is currently no way to pass any proxy options to the proxy creation process from the service manager config.

There could be basically two routes here:

  • Either do not add the destructor by default
    • this could potentially break some code
    • Kinda makes sense since we are not calling the class actively and therefore should not need a destructor
      • Putting it like this also could make this a proxy manager feature: adding destructor dynamically or better only calling it when the class is actually initialized
  • Add the possibility to define $proxyOptions for each lazy services registered
Q A
New Feature yes
RFC yes
BC Break yes&no

Summary

Have destructor of lazy services dealt with in a way that does not call them without the class being ever used in that run of PHP.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions