method_exists()
method_exists() — Checks if the class method exists.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Checks if the class method exists in the given object_or_class.
Signature
method_exists(object|string $object_or_class, string $method): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $object_or_class | object|string | An object instance or a class name |
| $method | string | The method name |
Return value
Returns true if the method given by method has been defined for the given object_or_class, false otherwise.
Example
A runnable snippet:
$directory = new Directory('.'); var_dump(method_exists($directory,'read'));
Output:
bool(true)
Changelog
| Version | Change |
|---|---|
| 7.4.0 | Class checks against inherited private methods now return false. |
See also
function_exists(), is_callable(), class_exists()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page method_exists() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.