略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionMethod::getDeclaringClass

2024-04-26

ReflectionMethod::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

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

说明

public ReflectionMethod::getDeclaringClass(): ReflectionClass

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

参数

此函数没有参数。

返回值

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

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/reflectionmethod.getdeclaringclass.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3