spl_object_hash()

spl_object_hash() — Return hash id for given object.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.2.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

This function returns a unique identifier for the object. This id can be used as a hash key for storing objects, or for identifying an object, as long as the object is not destroyed. Once the object is destroyed, its hash may be reused for other objects. This behavior is similar to spl_object_id().

Signature

spl_object_hash(object $object): string

Parameters

ParameterTypeWhat it takes
$objectobjectAny object.

Return value

A string that is unique for each currently existing object and is always the same for each object.

Example

A runnable snippet:

$id = spl_object_hash($object); $storage[$id] = $object;

See also

spl_object_id()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page spl_object_hash() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.