rgb192
asked on
clone vs reference in php
how does
clone
differ from
reference
clone
differ from
reference
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Because '&' &$anothervalue will continue to be modified except for when it is cloned?Not sure I understand the question
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because '&' &$anothervalue will continue to be modified except for when it is cloned?
Not sure I understand the question
will &$anothervalue will continue to be modified
will clone &$anothervalue will continue to be modified
Not sure I understand the question
will &$anothervalue will continue to be modified
will clone &$anothervalue will continue to be modified
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When an object is cloned - the anothervalue variable is copied so the clone has its own copy.
Any change made to the value in the clone will now be independent of that made to the variable in the object that WAS cloned.
clone copies the object.
reference is just a pointer to the same object.
Thanks
Any change made to the value in the clone will now be independent of that made to the variable in the object that WAS cloned.
clone copies the object.
reference is just a pointer to the same object.
Thanks
After seeing this question, I wrote an article to explain and demonstrate the difference:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12310-PHP-Variables-and-References.html
Thanks for the points, ~Ray
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12310-PHP-Variables-and-References.html
Thanks for the points, ~Ray
ASKER
Because '&' &$anothervalue will continue to be modified except for when it is cloned?
Ray:
In the Singleton design pattern you might make the __clone() method final and private to avoid accidental proliferation.
explain please
AngelIII:
=> it will not NOT change in $clonevar , except if the "something" is actually a reference itself.
how could an example of this happen?