array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'reflectionmethod.getdeclaringclass.php', 1 => 'ReflectionMethod::getDeclaringClass', ), 'up' => array ( 0 => 'class.reflectionmethod.php', 1 => 'ReflectionMethod', ), 'prev' => array ( 0 => 'reflectionmethod.getclosure.php', 1 => 'ReflectionMethod::getClosure', ), 'next' => array ( 0 => 'reflectionmethod.getmodifiers.php', 1 => 'ReflectionMethod::getModifiers', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/reflection/reflectionmethod/getdeclaringclass.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(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" }