php8.5
Home/ Manual/ reflection / reflectionmethod/ ReflectionMethod::getDeclaringClass

ReflectionMethod::getDeclaringClass

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Gets declaring class for the reflected method

Description

ReflectionMethod::getDeclaringClass(): ReflectionClass

Gets the declaring class for the reflected method.

Parameters Parameters

Return Values

A ReflectionClass object of the class that the reflected method is part of.

Examples

ReflectionMethod::getDeclaringClass example

php
<?php
class HelloWorld {

    protected function sayHelloTo($name) {
        return 'Hello ' . $name;
    }

}

$reflectionMethod = new ReflectionMethod(new HelloWorld(), 'sayHelloTo');
var_dump($reflectionMethod->getDeclaringClass());
?>

The above example will output:

output
object(ReflectionClass)#2 (1) {
  ["name"]=>
  string(10) "HelloWorld"
}

See Also

  • ReflectionMethod::isAbstract

Source: reference/reflection/reflectionmethod/getdeclaringclass.xml · from the official PHP manual (php/doc-en)