ReflectionClass::getMethods

(PHP 5, PHP 7)

ReflectionClass::getMethodsObtiene un array de métodos

Descripción

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

Obtiene un array de métodos de una clase.

Parámetros

filter

Filtra los resultados para incluir solamente los métodos con ciertos atributos. Lo predeterminado es no filtrar nada.

Cualquier combinación de ReflectionMethod::IS_STATIC, ReflectionMethod::IS_PUBLIC, ReflectionMethod::IS_PROTECTED, ReflectionMethod::IS_PRIVATE, ReflectionMethod::IS_ABSTRACT, ReflectionMethod::IS_FINAL.

Valores devueltos

Un array de objetos ReflectionMethod que reflejan cada método.

Ejemplos

Ejemplo #1 Uso básico de ReflectionClass::getMethods()

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

$clase = new ReflectionClass('Apple');
$métodos $clase->getMethods();
var_dump($métodos);
?>

El resultado del ejemplo sería:

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"
  }
}

Ejemplo #2 Filtrar los resultados de ReflectionClass::getMethods()

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

$clase = new ReflectionClass('Apple');
$métodos $clase->getMethods(ReflectionMethod::IS_STATIC ReflectionMethod::IS_FINAL);
var_dump($métodos);
?>

El resultado del ejemplo sería:

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"
  }
}

Ver también