ReflectionClass::getMethods

(PHP 5, PHP 7)

ReflectionClass::getMethods锟斤拷取锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷

说锟斤拷

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

锟斤拷取锟斤拷姆锟斤拷锟斤拷锟揭伙拷锟斤拷锟斤拷椤�

锟斤拷锟斤拷

filter

锟斤拷锟剿斤拷锟轿拷锟斤拷锟斤拷锟侥承╋拷锟斤拷缘姆锟斤拷锟斤拷锟侥拷喜锟斤拷锟斤拷恕锟�

ReflectionMethod::IS_STATIC锟斤拷 ReflectionMethod::IS_PUBLIC锟斤拷 ReflectionMethod::IS_PROTECTED锟斤拷 ReflectionMethod::IS_PRIVATE锟斤拷 ReflectionMethod::IS_ABSTRACT锟斤拷 ReflectionMethod::IS_FINAL 锟侥帮拷位锟斤拷OR锟斤拷锟斤拷锟酵会返锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟皆★拷

Note: 锟斤拷注锟解:锟斤拷锟斤拷位锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 ~ 锟睫凤拷锟斤拷预锟斤拷锟斤拷锟叫★拷锟斤拷锟斤拷锟斤拷锟揭诧拷锟斤拷锟剿碉拷锟斤拷薹锟斤拷锟饺★拷锟斤拷械姆蔷锟教拷锟斤拷锟斤拷锟�

锟斤拷锟斤拷值

锟斤拷锟斤拷每锟斤拷锟斤拷锟斤拷 ReflectionMethod 锟斤拷锟斤拷锟�锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷

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

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

锟轿硷拷