|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-06-25 12:35 UTC] olamedia at gmail dot com
Description:
------------
Requesting new functions:
get_object_id() to get identifier of the object like in var_dump() (Object #XXX)
get_object_by_id() to get object by identifier
Related bug in test script
Test script:
---------------
class a{
protected $b;
public function __construct($b){
$this->b = $b;
}
}
class b{
}
$b = new b()
$a = new a($b);
unset($b); // __destruct will not be called because of link left in $a
Expected result:
----------------
class a{
protected $b;
public function __construct($b){
$this->b = get_object_id($b); // integer
}
public function getB(){
return get_object_by_id($this->b);
}
}
class b{
}
$b = new b()
$a = new a($b);
var_dump($a->getB()); // Object #
unset($b); // __destruct will be called because no links left
var_dump($a->getB()); // boolean false
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 11:00:01 2025 UTC |
I can describe it better: I know that when I'm calling $object->property->method(), $object IS STILL ALIVE, but I can't access $object in this method() because if I'll hold reference to $object in this $property, I'll be required to call GC or destroy $object and all properties manually: foreach ($iterator as $object){ // do something $object->destroy(); // ... foreach ($this->properties as $property) $property- >destroy(); } ... function doSomething(){ $object = new object(); $object2 = new object(); $object3 = new object(); $object4 = new object(); // do something destroy($object, $object2, $object3, $object4); }