(PHP 5, PHP 7, PHP 8)
ReflectionClass::getMethods — Obtém um array de métodos
Obtém um array de métodos para a classe.
filterFiltre os resultados para incluir apenas métodos com determinados atributos. Padrões sem filtragem.
Qualquer disjunção bit a bit de ReflectionMethod::IS_STATIC,
ReflectionMethod::IS_PUBLIC,
ReflectionMethod::IS_PROTECTED,
ReflectionMethod::IS_PRIVATE,
ReflectionMethod::IS_ABSTRACT,
ReflectionMethod::IS_FINAL,
para que todos os métodos com qualquer dos dados
atributos serão retornados.
Nota: Observe que outras operações bit a bit, por exemplo
~não funcionará como esperado. Em outras palavras, não é possível recuperar todos os métodos não estáticos, por exemplo.
Um array de objetos ReflectionMethod refletindo cada método.
| Versão | Descrição |
|---|---|
| 7.2.0 |
filter agora é anulável.
|
Exemplo #1 Uso básico de 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);
?>O exemplo acima produzirá:
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"
}
}
Exemplo #2 Filtrando resultados vindos de 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);
?>O exemplo acima produzirá:
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"
}
}