Current Location: Home> Function Categories> spl_object_id

spl_object_id

Returns the integer object handle of the given object
Name:spl_object_id
Category:SPL
Programming Language:php
One-line Description:Get the unique identifier of the object

Function name: spl_object_id()

Applicable version: PHP 5 >= 5.2.0, PHP 7

Function description: The spl_object_id() function is used to obtain the unique identifier of the object.

Usage: int spl_object_id ( object $obj )

parameter:

  • $obj: The object to get the identifier.

Return value: Returns an integer representing the object's unique identifier.

Example:

 class MyClass { public $name; } $obj1 = new MyClass(); $obj2 = new MyClass(); $obj1->name = "Object 1"; $obj2->name = "Object 2"; $id1 = spl_object_id($obj1); $id2 = spl_object_id($obj2); echo "Object 1 ID: " . $id1 . "\n"; echo "Object 2 ID: " . $id2 . "\n";

Output:

 Object 1 ID: 1 Object 2 ID: 2

In the example above, we create two MyClass objects $obj1 and $obj2 and assign a value to their attribute name. Then, we use the spl_object_id() function to get the unique identifier of the object and print it out. As you can see, the identifier of $obj1 is 1 and the identifier of $obj2 is 2. Each object has a unique identifier, even if their attribute values ​​are the same.

Related
Similar Functions
Popular Articles