PHPマニュアル/PEARマニュアル | ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot

ReflectionClass::getMethods - メソッドの配列を取得する | JavaScript入門&応用&リファレンスなら「JavaScriptist」

  

ReflectionClass::getMethods

(PHP 5, PHP 7)

ReflectionClass::getMethodsメソッドの配列を取得する

説明

public array ReflectionClass::getMethods ([ int $filter ] )

クラスのメソッドの配列を取得します。

パラメータ

filter

結果をフィルタして、特定の属性を持つメソッドだけを含めるようにします。 デフォルトは、何もフィルタしません。

ReflectionMethod::IS_STATICReflectionMethod::IS_PUBLICReflectionMethod::IS_PROTECTEDReflectionMethod::IS_PRIVATEReflectionMethod::IS_ABSTRACTReflectionMethod::IS_FINAL の任意の組み合わせ。 指定した属性の いずれか を持つすべてのメソッドを返します。

注意: その他のビット演算 (~ など) は期待通りの挙動にはなりません。 つまり、たとえば static ではないメソッドをすべて取得するなどといったことはできません。

返り値

各メソッドを表す ReflectionMethod オブジェクトの配列を返します。

例1 ReflectionClass::getMethods() の基本的な使用例

<?php
class Apple {
    public function 
firstMethod() { }
    final protected function 
secondMethod() { }
    private static function 
thirdMethod() { }
}

$class = new ReflectionClass('Apple');
$methods $class->getMethods();
var_dump($methods);
?>

上の例の出力は以下となります。

array(3) {
  [0]=>
  &object(ReflectionMethod)#2 (2) {
    ["name"]=>
    string(11) "firstMethod"
    ["class"]=>
    string(5) "Apple"
  }
  [1]=>
  &object(ReflectionMethod)#3 (2) {
    ["name"]=>
    string(12) "secondMethod"
    ["class"]=>
    string(5) "Apple"
  }
  [2]=>
  &object(ReflectionMethod)#4 (2) {
    ["name"]=>
    string(11) "thirdMethod"
    ["class"]=>
    string(5) "Apple"
  }
}

例2 ReflectionClass::getMethods() のフィルタリング

<?php
class Apple {
    public function 
firstMethod() { }
    final protected function 
secondMethod() { }
    private static function 
thirdMethod() { }
}

$class = new ReflectionClass('Apple');
$methods $class->getMethods(ReflectionMethod::IS_STATIC ReflectionMethod::IS_FINAL);
var_dump($methods);
?>

上の例の出力は以下となります。

array(2) {
  [0]=>
  &object(ReflectionMethod)#2 (2) {
    ["name"]=>
    string(12) "secondMethod"
    ["class"]=>
    string(5) "Apple"
  }
  [1]=>
  &object(ReflectionMethod)#3 (2) {
    ["name"]=>
    string(11) "thirdMethod"
    ["class"]=>
    string(5) "Apple"
  }
}

参考


忘却曲線を使ってこの知識を確実に記憶に残す

フォーラムで「ReflectionClass::getMethods - メソッドの配列を取得する」について話す
各種マニュアル: PHPマニュアル | PEARマニュアル | Smarty(英語)マニュアル | PHP-GTKマニュアル | ReflectionClass::getMethods - メソッドの配列を取得する」をGoogle検索
copyright © 1997-2024 PHP ドキュメント作成グループ(ライセンス). provided by php spot. マニュアル: