-
Notifications
You must be signed in to change notification settings - Fork 41
clone and Stale Reference
clone
is the Solution 2nd for data pollution.
-
clone
creates new objects. Give an object X1, and another object Y holding a ref to X1, in a new request X1 is cloned to produce a new object X2, but object Y is still holding X1, not X2. So developers and users should pay some attention to this kind of relations. -
The second problem is that by default
clone
does not clone props of type closure or object. -
The third problem is that clone maybe sometimes destroy the method
rebinding
in Laravel container. -
Static props would better not change.
Objects url and routes have ref in Laravel official objects , but rarely have ref in your code. So clone
is used for url and routes.
While other objects, such as event, are used widely in your code, so clone
is not used, Solution 3 is used.