ReflectionClass::getMethods

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getMethodsYöntemleri dizi olarak döndürür

Açıklama

public ReflectionClass::getMethods(?int $süzgeç = null): array

Sınıfın yöntemlerini bir dizi olarak döndürür.

Bağımsız Değişkenler

süzgeç

Dizinin belirli öznitelikleri içeren yöntemleri içermesini sağlayacak süzgeç.

ReflectionMethod::IS_STATIC, ReflectionMethod::IS_PUBLIC, ReflectionMethod::IS_PROTECTED, ReflectionMethod::IS_PRIVATE, ReflectionMethod::IS_ABSTRACT, ReflectionMethod::IS_FINAL sabitlerinin bitsel VEYAsı; belirtilen özniteliklerden herhangi birini içeren her yöntem döndürülür.

Bilginize: ~ gibi diğer bitsel işlemler beklendiği gibi çalışmayabilir. Örneğin, statik olmayan yöntemlerin tamamını döndürmek mümkün olmaz.

Dönen Değerler

Her yöntemi yansıtan ReflectionMethod nesnelerininin bir dizisi.

Sürüm Bilgisi

Sürüm: Açıklama
7.2.0 süzgeç artık null olabiliyor.

Örnekler

Örnek 1 - ReflectionClass::getMethods() temel kullanım örneği

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

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

Yukarıdaki örneğin çıktısı:

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

Örnek 2 - ReflectionClass::getMethods() ve sonuçların süzülmesi

<?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);
?>

Yukarıdaki örneğin çıktısı:

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

Ayrıca Bakınız