SplObjectStorage::getHash() - 数据结构
SplObjectStorage::getHash()
(PHP 5 >= 5.4.0, PHP 7)
Calculate a unique identifier for the contained objects
说明
publicSplObjectStorage::getHash(object $object) : stringThis method calculates an identifier for the objects added to an SplObjectStorage object.
The implementation in SplObjectStorage returns the same value as spl_object_hash().
The storage object will never contain more than one object with the same identifier. As such, it can be used to implement a set (a collection of unique values) where the quality of an object being unique is determined by the value returned by this function being unique.
参数
$objectThe object whose identifier is to be calculated.
返回值
A string with the calculated identifier.
错误/异常
A RuntimeException is thrown when the returned value is not a string.
范例
SplObjectStorage::getHash() example
以上例程的输出类似于:
2 3
参见
spl_object_hash()
返回指定对象的hash id
This also appears to be the function which gets used within the contains() function, so if all the objects you are storing already have a unique id you can overwrite this function with your own class.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!