Req #52300 [Opn]: spl_get_object_by_hash()
| From: | cataphract@php.net | Date: | Sun, 11 Jul 2010 10:26:17 +0000 |
| Subject: | Req #52300 [Opn]: spl_get_object_by_hash() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152265@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52300&edit=1
ID: 52300
Updated by: cataphract@php.net
Reported by: olamedia at gmail dot com
Summary: spl_get_object_by_hash()
Status: Open
Type: Feature/Change Request
Package: SPL related
PHP Version: 5.3.3RC2
New Comment:
If you want weak references, this seems like a poor substitute. Who
would want to store a reference that may yield another object in the
future?
Previous Comments:
------------------------------------------------------------------------
[2010-07-09 07:41:21] olamedia at gmail dot com
Description:
------------
class a{}
$object = new a();
$object2 = spl_get_object_by_hash(spl_object_hash($object));
var_dump($object === $object2); // true (same object)
NOTE: When using spl_get_object_by_hash, you must know that $object must
be alive
else function can return another object.
Primary usage example in test script:
Test script:
---------------
class a{
protected $_b;
public function getB(){
return spl_get_object_by_hash($this->_b);
}
public function doSomething(){
$b = $this->getB();
// here I can use $b !
}
public function __construct($b){
$this->_b = spl_object_hash($b);
}
}
class b{
protected $_a;
public function getA(){
return $this->_a;
}
public function __construct(){
$this->_a = new a($this);
}
public function __destruct(){
echo 'destroyed';
}
}
$b = new b();
$b->getA()->doSomething();
unset($b); // destroyed !! this IS NOT POSSIBLE without
spl_get_object_by_hash()
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52300&edit=1