표준 PHP 라이브러리(SPL) SplObjectStorage::getHash

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

SplObjectStorage::getHash — 포함된 개체의 고유 식별자 계산


설명

public SplObjectStorage::getHash(object $object): string

이 메서드는 SplObjectStorage 개체에 추가된 개체의 식별자를 계산합니다.

SplObjectStorage의 구현은 spl_object_hash()와 동일한 값을 반환합니다.

저장소 개체에는 동일한 식별자를 가진 개체가 두 개 이상 포함되지 않습니다. 따라서 고유한 개체의 품질이 고유한 이 함수에 의해 반환된 값에 의해 결정되는 집합(고유한 값의 모음)을 구현하는 데 사용할 수 있습니다.


매개변수

object
식별자를 계산할 개체입니다.

반환 값

계산된 식별자가 있는 문자열입니다.


오류/예외

반환된 값이 문자열이 아닌 경우 RuntimeException이 throw됩니다.


Examples

예제 #1 SplObjectStorage::getHash() 예제

                  
<?php
class OneSpecimenPerClassStorage extends SplObjectStorage {
    public function getHash($o) {
        return get_class($o);
    }
}
class A {}

$s = new OneSpecimenPerClassStorage;
$o1 = new stdClass;
$o2 = new stdClass;
$o3 = new A;

$s[$o1] = 1;
//$o2 is considered equal to $o1 so the value is replaced
$s[$o2] = 2;
$s[$o3] = 3;

//these are considered equal to the objects before
//so they can be used to access the values stored under them
$p1 = new stdClass;
$p2 = new A;
echo $s[$p1], "\n";
echo $s[$p2], "\n";
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

2
3
                

기타