SplObjectStorage::getHash()函式是用於獲取物件的雜湊值。它返回一個唯一的識別符號,用於在SplObjectStorage物件中標識物件。
用法:
string SplObjectStorage::getHash ( object $object )
引數:
- $object: 要獲取雜湊值的物件。
返回值:
- 返回一個字串,表示物件的雜湊值。
示例:
// 建立一個SplObjectStorage物件
$storage = new SplObjectStorage();
// 建立兩個物件
$object1 = new stdClass();
$object2 = new stdClass();
// 將物件新增到SplObjectStorage物件中
$storage->attach($object1);
$storage->attach($object2);
// 獲取物件的雜湊值
$hash1 = $storage->getHash($object1);
$hash2 = $storage->getHash($object2);
echo "Object 1 hash: " . $hash1 . "\n";
echo "Object 2 hash: " . $hash2 . "\n";
輸出結果:
Object 1 hash: 0000000061140f5f000000004b1c8e6c
Object 2 hash: 0000000061140f63000000004b1c8e6c
在這個示例中,我們建立了一個SplObjectStorage物件,並向其新增了兩個物件。然後,使用getHash()函式獲取每個物件的雜湊值,並將其輸出到螢幕上。注意,每個物件的雜湊值是唯一的,即使它們是相同型別的物件。