CakeFest 2024: The Official CakePHP Conference

ReflectionReference::getId

(PHP 7 >= 7.4.0, PHP 8)

ReflectionReference::getId获取引用的唯一 ID

说明

public ReflectionReference::getId(): string

返回一个 ID,该 ID 在该引用的生命周期内对于该引用是唯一的。 此 ID 可用于比较引用的相等性,或维护已知引用的映射。

参数

此函数没有参数。

返回值

返回一个未指定格式的 string

示例

示例 #1 基本的 ReflectionReference::getId() 用法

<?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());
?>

以上示例会输出:

bool(false)
bool(true)
add a note

User Contributed Notes

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