Home > Article > Backend Development > How to determine whether a specified method is defined in a class in PHP
You can use the method_exists() function in php to determine whether the specified method is defined in the class. This function can check whether the specified method of the class exists. The syntax is "method_exists($object,$method_name)"; if it is defined It returns true, otherwise it returns false.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use method_exists () function to determine whether the specified method is defined in the class.
Example:
$directory=new Directory; if(!method_exists($directory,'read')){ echo '未定义read方法!'; }
Description:
The method_exists() function can check whether the specified method of the class exists. Syntax:
method_exists(mixed $object, string $method_name): bool
This function checks whether the class method exists in the specified object.
object: object example or class name.
method_name: method name.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to determine whether a specified method is defined in a class in PHP. For more information, please follow other related articles on the PHP Chinese website!