Home > Article > Backend Development > How to determine whether a method in php exists
How to determine whether a method in php exists: You can use the method_exists function to determine, such as [method_exists($directory,'read')]. If you want to determine whether the properties in the class have been defined, you can use the property_exists function to determine.
Related functions:
(Learning video recommendation: java course)
bool method_exists ( mixed $object , string $method_name ) Check whether the method of the class exists
Code example:
$directory=new Directory; if(!method_exists($directory,'read')) { echo '未定义read方法!'; }
If you want to determine whether a certain attribute in the class has been defined, use the following method:
bool property_exists ( mixed $class , string $property ) Check whether the properties of the class exist
Code example:
$directory=new Directory; if(!property_exists($directory,'li')) { echo '未定义li属性!'; }
Related recommendations: php training
The above is the detailed content of How to determine whether a method in php exists. For more information, please follow other related articles on the PHP Chinese website!