php8.5
Home/ Manual/ reflection / reflectionreference/ ReflectionReference::getId

ReflectionReference::getId

PHP function Edit on GitHub ✎

(PHP 7 >= 7.4.0, PHP 8)

Get unique ID of a reference

Description

ReflectionReference::getId(): string

Returns an ID which is unique for the reference for the lifetime of that reference. This ID can be used to compare references for equality, or to maintain a map of known references.

Parameters Parameters

Return Values

Returns a String of unspecified format.

Examples

Basic ReflectionReference::getId usage

php
<?php
$val1 = 'foo';
$val2 = 'bar';
$arr = [&$val1, &$val2, &$val1];

$rr1 = ReflectionReference::fromArrayElement($arr, 0);
$rr2 = ReflectionReference::fromArrayElement($arr, 1);
$rr3 = ReflectionReference::fromArrayElement($arr, 2);

var_dump($rr1->getId() === $rr2->getId());
var_dump($rr1->getId() === $rr3->getId());
?>

The above example will output:

output
bool(false)
bool(true)

Source: reference/reflection/reflectionreference/getid.xml · from the official PHP manual (php/doc-en)