GithubHelp home page GithubHelp logo

Use a factory for DeepCopy about deepcopy HOT 4 CLOSED

theofidry avatar theofidry commented on September 18, 2024
Use a factory for DeepCopy

from deepcopy.

Comments (4)

mnapoli avatar mnapoli commented on September 18, 2024

A factory is only responsible for creating an object, not caching it -> that would make the whole thing a singleton/static accessor (which is of course not a good idea).

Today dealing with the instance of the service is the responsibility of the user, just like with any other package AFAIK (e.g. Symfony's translator, Twig's instance, etc. etc.). When using a DI container it's not an issue at all (you configure DeepCopy once, it gets created once and injected everywhere needed).

from deepcopy.

theofidry avatar theofidry commented on September 18, 2024

Giving an alternative to DI is good as well. To take the example of Symfony components, you do have PropertyAccess which a factory implementing the singleton pattern.

I'm actually more concerned about the cache system of DeepCopy: it uses spl_object_hash which can be given to two very different objects if the first one has been unset. If you create a new instance you reduce the chances to have this issue, but I have no idea how much you raise the likelihood of having this issue by having a single instance.

from deepcopy.

mnapoli avatar mnapoli commented on September 18, 2024

The hashmap is reset each time copy() is called (https://github.com/myclabs/DeepCopy/blob/master/src/DeepCopy/DeepCopy.php#L55). Yes it's not the cleanest solution ever ;) but well it works

from deepcopy.

theofidry avatar theofidry commented on September 18, 2024

Oh I missed that. Hm ok so there is no real point for a factory then...

from deepcopy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.