CakeFest 2024: The Official CakePHP Conference

ReflectionMethod::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

ReflectionMethod::getDeclaringClass获取被反射的方法所在类的反射实例

说明

public ReflectionMethod::getDeclaringClass(): ReflectionClass

获取被反射的方法所在的类的反射实例。

参数

此函数没有参数。

返回值

返回类的 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"
}

参见

add a note

User Contributed Notes

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