ReflectionMethod::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

ReflectionMethod::getDeclaringClass獲取被反射的方法所在類的反射實例

說明

public ReflectionMethod::getDeclaringClass(): ReflectionClass

獲取被反射的方法所在的類的反射實例。

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

返回一個類的 ReflectionClass 反射對象,被反射的方法是這個類的一部分。

范例

示例 #1 ReflectionMethod::getDeclaringClass() example

<?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"
}

參見