【发布时间】:2015-10-05 10:23:55
【问题描述】:
PHP:如何从他的哈希中获取一个对象? [如何恢复 spl_object_hash ]
示例:
$a = new A();
$adressOfA = spl_object_hash($a);
//... laters ...
// I want to get the instance stored in the $adressOfA, kind of
$theSameAButInAnotherVariable = some_function($adressOfA);
感谢您提前提供的帮助。
【问题讨论】:
-
我认为你误解了 spl_object_hash($a); 的目的它不是原始对象的指针/引用/地址,只是对象的唯一 id....如果您需要将其用作指针,则使用 $adressOfA 作为键构建对象数组