略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Hashable

2024-11-14

The Hashable interface

(No version information available, might only be in Git)

简介

Hashable is an interface which allows objects to be used as keys. It’s an alternative to spl_object_hash(), which determines an object’s hash based on its handle: this means that two objects that are considered equal by an implicit definition would not treated as equal because they are not the same instance.

hash() is used to return a scalar value to be used as the object's hash value, which determines where it goes in the hash table. While this value does not have to be unique, objects which are equal must have the same hash value.

equals() is used to determine if two objects are equal. It's guaranteed that the comparing object will be an instance of the same class as the subject.

接口摘要

class Ds\Hashable {
/* 方法 */
abstract public equals(object $obj): bool
abstract public hash(): mixed
}

目录

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/class.ds-hashable.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3