Home > Article > Backend Development > How to check if a class method exists in php
In PHP, you can use the method_exists() function to check whether a class method exists. This function can check whether a class method exists in the specified object. The syntax is "method_exists($object,$method_name)"; if Returns true if it exists, otherwise returns false.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php check whether the class method exists You can use the method_exists() function.
method_exists - Check whether the method of the class exists, check whether the method of the class exists in the specified object.
Syntax:
method_exists($object,$method_name)
Parameters:
object: object example or class name.
method_name: method name.
Return value: If the method pointed by method_name has been defined in the object class pointed by object, then return true, otherwise return false.
Example:
<?php $directory = new Directory('.'); var_dump(method_exists($directory,'read')); ?>
Output result:
bool(true)
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to check if a class method exists in php. For more information, please follow other related articles on the PHP Chinese website!