PHP 8.0.0 Released!

ReflectionReference::getId

(PHP 7 >= 7.4.0)

ReflectionReference::getIdGet unique ID of a reference

Description

public ReflectionReference::getId ( ) : mixed

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

This function has no parameters.

Return Values

Returns an int or string of unspecified format.

Examples

Example #1 Basic ReflectionReference::getId() usage

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

$rr1 ReflectionReference::fromArrayElement($arr0);
$rr2 ReflectionReference::fromArrayElement($arr1);
$rr3 ReflectionReference::fromArrayElement($arr2);

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

The above example will output:

bool(false)
bool(true)
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top