BiliHelper-personal/packages/php-ds/src/Hashable.php
2025-02-18 18:49:19 +08:00

33 lines
987 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Ds;
/**
* Hashable is an interface which allows objects to be used as keys.
*
* Its an alternative to spl_object_hash(), which determines an objects 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.
*
* @package Ds
*/
interface Hashable
{
/**
* Produces a scalar value to be used as the object's hash, 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.
*
* @return mixed
*/
public function hash();
/**
* Determines if two objects should be considered equal. Both objects will
* be instances of the same class but may not be the same instance.
*
* @param mixed $obj An instance of the same class to compare to.
*/
public function equals($obj): bool;
}