i have doubts php objects behave after have been deleted in cases, doing tests. code:
class itemrecord { private $id; protected $name; public function __contruct($pid, $pname) { $this->id = $pid; $this->name = $pname; } public function setname($pname) { $this->name = $pname; } public function getname() { return $this->name; } }
i create objects of itemrecord class , then, append them object list (an array):
$objlist = array(); $obj1 = new itemrecord("1", "object 1"); $objlist[] = $obj1; $obj2 = new itemrecord("2", "object 2"); $objlist[] = $obj2;
if change property in 'original' object, example:
$obj1->setname("foo");
and i'll try show content of 'linked' element in list original object:
echo($objlist[0]->getname()); //-> of course, displays "foo"
so if delete object should not exist in list anymore
unset($obj1); unset($obj2);
but it's not that!
echo($objlist[0]->getname());
it continues displaying "foo"!, , the object continues existing well...
so question is: in case, when delete object, copy operation occurs @ delete time?
there other curious cases strange behavior,
updated: after answers , things have been talked in comments. maybe great if unset() function return result of deleting. example: 'true', if var content or object removed.
to answer question : no.
when unset value removing reference variable not deleting that. deleted when there no reference variable exits.
from php documentation (http://php.net/manual/en/function.unset.php)
unset() destroys specified variables
Comments
Post a Comment