I'm creating a class, that clones itself whenever it gets a new value.
Each instance has a set of properties that are related to the value it gets:
Expand|Select|Wrap|Line Numbers
- class Atom
- {
- private $_currentValue;
- private $_origin;
- private $_outdatedAtom;//reference to its old state
- public function setValue($value, $origin)
- {
- if (null !== $this->_currentValue) {
- $this->_outdatedAtom = clone $this;
- }
- $this->_origin = $origin;
- $this->_currentValue = $value;
- }
- public function unsetOutdatedAtom()
- {
- //help here!
- }
- }
So if y pass a new value to setValue() 10 times, i get a nested reference of 9 objects,
I want to create a method that would allow to cut the reference chain from the instance it is called in.
Expand|Select|Wrap|Line Numbers
- //unset the the $atom outdatedAtom's outdatedAtom reference
- $atom->getOutdatedAtom()->unsetOutdatedAtom();
- //this would leave us with just one reference, the current atom's outdatedAtom, all references down the chain are lost
I ask this because i dont want to have a big chain of outdated atoms that get dereferenced and occupy memory space.
I dont know if i made myself clear.