CKTIS / PHP
method_exists()
Sprawdza, czy metoda jest zdefiniowana, także gdy jest prywatna w badanej klasie.
Wersja: PHP 8.4; repository runtime, production runtime not attested
Składnia
method_exists(object|string $object_or_class, string $method): boolSprawdza, czy metoda jest zdefiniowana, także gdy jest prywatna w badanej klasie. Wynik true nie daje dostępu wywołującemu. Nazwy obsługiwane wyłącznie przez __call są pomijane. Nieznana nazwa klasy może uruchomić autoload.
Sygnatura
method_exists(object|string $object_or_class, string $method): bool
Wynik przykładu
[true,false,7]
Przykłady
<?php
class Gauge { private function reset() {} public function __call($name,$args) { return 7; } }
$g=new Gauge(); echo json_encode([method_exists($g,"reset"),method_exists($g,"read"),$g->read()]);
Wynik
[true,false,7]