(PHP 5, PHP 7, PHP 8)
ReflectionMethod::getDeclaringClass — 取得反射方法的宣告類別
此函式沒有參數。
一個 ReflectionClass 物件,表示反射方法所屬的類別。
範例 #1 ReflectionMethod::getDeclaringClass() 範例
<?php
class HelloWorld {
protected function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
$reflectionMethod = new ReflectionMethod(new HelloWorld(), 'sayHelloTo');
var_dump($reflectionMethod->getDeclaringClass());
?>
以上範例會輸出
object(ReflectionClass)#2 (1) { ["name"]=> string(10) "HelloWorld" }