Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / PHP

method_exists()

Overí definíciu metódy vrátane súkromnej metódy deklarovanej v skúmanej triede.

Verzia: PHP 8.4; repository runtime, production runtime not attested

Syntax

method_exists(object|string $object_or_class, string $method): bool

Overí definíciu metódy vrátane súkromnej metódy deklarovanej v skúmanej triede. Výsledok true neudeľuje prístup. Názvy obslúžené iba cez __call nenájde. Neznáma trieda môže spustiť automatické načítanie.

Signatúra

method_exists(object|string $object_or_class, string $method): bool

Výstup príkladu

[true,false,7]

Príklady

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

Výsledok

[true,false,7]

Zdroje