|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-07-11 12:26 UTC] cataphract@php.net
[2010-07-11 13:24 UTC] olamedia at gmail dot com
[2010-08-07 01:53 UTC] johannes@php.net
-Status: Open
+Status: Wont fix
[2010-08-07 01:53 UTC] johannes@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 15:00:01 2025 UTC |
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()