PHP Conference Japan 2024

ReflectionProperty::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

ReflectionProperty::getDeclaringClass取得宣告類別

說明

public ReflectionProperty::getDeclaringClass(): ReflectionClass

取得宣告類別。

參數

此函式沒有參數。

回傳值

一個 ReflectionClass 物件。

參見

新增筆記

使用者貢獻的筆記 1 則筆記

metamarkers at gmail dot com
11 年前
如果您正在反射一個物件,並取得一個已設定但未在任何類別中宣告的屬性的宣告類別,它會返回實例的類別。

<?php

class X {

}

$x = new X();
$x->foo = 'bar';
$reflection = new ReflectionObject($x);
echo
$reflection->getProperty('foo')->getDeclaringClass()->getName(); // X

?>
To Top