Unsetting variable at reference in php

manager59151726

New Member
I have a class which contains an array of objects and has methods to return an object from that array by reference. There is also a method to unset an object from the array.However if I have a variable that references an object from the array, and that element is unset, the variable still has a reference to it. What do I need to do in the remove method that will destroy that object for good, including references to it.\[code\]class myClass{ public $objectList = array(); public function __construct() { $objectList[] = new myObject(); } public function &getObjectByReference() { return $this->objectList[0]; } public function removeObject() { unset($this->objectList[0]); }}$myClass = new myClass();$referencedObject = $myClass->getObjectByReference(); // this can now use the methods from myObject$myClass-> removeObject(); // supposed to delete the object from memory. However $referencedObject is still// able to use all the methods from myObject.\[/code\]So thats the problem I am having, I need to be able to remove from the array and delete the object from memory so variables that reference that object are no longer usable.
 
Back
Top