array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.spl-object-hash.php', 1 => 'spl_object_hash', ), 'up' => array ( 0 => 'ref.spl.php', 1 => 'SPL 函数', ), 'prev' => array ( 0 => 'function.spl-classes.php', 1 => 'spl_classes', ), 'next' => array ( 0 => 'function.spl-object-id.php', 1 => 'spl_object_id', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/spl/functions/spl-object-hash.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
spl_object_hash — 返回指定对象的 hash id
本函数为对象返回唯一标识符。只要对象没有销毁,这个 id 可用作保存对象的散列键,或者用于标识对象。一旦对象销毁,它的散列值可能会被其它对象重用。此行为类似为 spl_object_id()。
object
任何对象。
字符串,对于当前存在的每个对象都是唯一的,且对同一个对象始终相同。
示例 #1 A spl_object_hash() 示例
<?php
$id = spl_object_hash($object);
$storage[$id] = $object;
?>
注意:
当对象销毁后,它的散列值可能会被其它对象重用。
注意:
对象散列应该使用
===
和!==
标识符比较,因为返回的散列可能是数字字符串。例如:0000000000000e600000000000000000
。