downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ReflectionClass::getModifiers> <ReflectionClass::getMethod
[edit] Last updated: Fri, 24 May 2013

view this page in

ReflectionClass::getMethods

(PHP 5)

ReflectionClass::getMethodsВозвращает список методов в виде массива

Описание

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

Возвращает список методов в виде массива.

Список параметров

filter

Фильтрация результата для включения в список только методов с определенными атрибутами. По умолчанию, фильтров нет.

Любая комбинация из следующих констант: ReflectionMethod::IS_STATIC, ReflectionMethod::IS_PUBLIC, ReflectionMethod::IS_PROTECTED, ReflectionMethod::IS_PRIVATE, ReflectionMethod::IS_ABSTRACT, ReflectionMethod::IS_FINAL.

Возвращаемые значения

Массив (array) объектов класса 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::getModifiers> <ReflectionClass::getMethod
[edit] Last updated: Fri, 24 May 2013
 
add a note add a note User Contributed Notes ReflectionClass::getMethods - [3 notes]
up
1
erik at dubbelboer dot com
1 year ago
The $filter uses an OR to filter the methods.

So php ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC will return all methods which are static or public methods, NOT only the methods which are both static and private.
up
1
deminy at deminy dot net
1 year ago
Method ReflectionClass::getMethods doesn't work constantly across different versions of PHP. For following code piece

<?php
class Dummy implements Iterator
{
    public function
current () {}
    public function
next () {}
    public function
key () {}
    public function
valid () {}
    public function
rewind () {}
}

$reflection = new ReflectionClass('Dummy');
$aMethods = $reflection->getMethods();
echo
'# of methods: ', count($aMethods), "\n";
?>

, it outputs "# of methods: 10" on PHP 5.2.14 and PHP 5.2.17, including all methods defined in the class itself and in the interface no matter if a method has been implemented or overridden; however, it returns "# of methods: 5" on PHP 5.3.5. Based on some other tests did by my colleagues, I assume it also returns "# of methods: 5" on PHP 5.2.10 and PHP 5.3.6.
up
-1
calibhaan at gmail dot com
3 years ago
This method return an array of ReflectionMethod;
For example:

<?php
$reflection
= new ReflectionClass('Test');
$aMethods = $reflection->getMethods();
var_dump($aMethods);
?>

Display:
array(2) {
 [0]=> &object(ReflectionMethod)#7 (2) {
  ["name"]=> string(11) "__construct"
  ["class"]=> string(9) "Test" }
 [1]=> &object(ReflectionMethod)#8 (2) {
  ["name"]=> string(3) "run"
  ["class"]=> string(9) "Test" }
}

 
show source | credits | stats | sitemap | contact | advertising | mirror sites