-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
Cloning lazy instantiated objects #333
Comments
@Ocramius sorry I pressed the enter key too soon. |
Also guess kind of related to myclabs/DeepCopy#18 |
A cyclic graph can only be built like that in PHP, since there is no construct that allows instantiation and bi-directional reference of objects at the same time. This is normal for imperative languages, so I' don't see a way around it.
This is a workaround, but it still isn't an "immutable cyclic graph". It just looks immutable from the outside. Even if you disabled lazy instantiation in a specific method of your proxies ( I don't want to support different In addition to that, |
Makes sense, so the problem comes from the way I'm solving those |
If you have a proxy used to lazy instantiated object, cloning it will result in the instantiation of the said object. Is there any way to prevent that? Because this makes it impossible to use lazy instantiation in an immutable system.
To give a more real world use case, in the case of https://github.com/nelmio/alice, sometimes generating a fixture object may result in resolving other objects. For example if you have:
When generating
dummy1
,@dummy*
will matchdummy0
and sodummy0
will be generated beforedummy1
. In certain cases however, for example:This strategy fails because you may have cyclic dependencies. Those cyclic dependences are actually perfectly valid and is not something that should be avoided, but it will fail is because for example
dummy1
needsdummy2
to be generated first, anddummy2
needsdummy3
, butdummy3
needsdummy1
, which cannot be generated yet...There is two ways to fix that:
dummy1
needsdummy2
, you stop at that and you don't care yet howdummy2
is generated.The issue is that the library enforces immutability almost everywhere, for example
here, making use of https://github.com/myclabs/DeepCopy. The resulting issue is that some cloning are done too early for the usage of a proxy to be of any use.
The text was updated successfully, but these errors were encountered: