CKTIS / PHP
method_exists()
Check whether a method is defined, including a private method declared on the class itself.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
method_exists(object|string $object_or_class, string $method): boolCheck whether a method is defined, including a private method declared on the class itself. A positive result does not grant the caller access. Names handled only through __call are absent. Looking up an unknown class name may invoke autoloaders.
Signature
method_exists(object|string $object_or_class, string $method): bool
Example output
[true,false,7]
Examples
<?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()]);
Result
[true,false,7]