Req #52182 [Opn->Bgs]: get_object_by_id and get_object_id
| From: | johannes@php.net | Date: | Fri, 25 Jun 2010 11:17:14 +0000 |
| Subject: | Req #52182 [Opn->Bgs]: get_object_by_id and get_object_id | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151861@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52182&edit=1
ID: 52182
Updated by: johannes@php.net
Reported by: olamedia at gmail dot com
Summary: get_object_by_id and get_object_id
-Status: Open
+Status: Bogus
Type: Feature/Change Request
Package: Unknown/Other Function
PHP Version: 5.3.2
New Comment:
Your design looks broken. Why should unset a random pointer to the
object destroy it? If you really need to unset them - which I'd most
likely consider broken design - add a method to invalidate it this ...
If you really want to do this the needed function is available -
spl_object_hash().
But mind that we don't have any true unique identifier - once an object
is destroyed it's ID might be re-used by others.
Previous Comments:
------------------------------------------------------------------------
[2010-06-25 12:35:55] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52182&edit=1