Home>Article>Backend Development> How to determine whether a method in php exists

How to determine whether a method in php exists

王林
王林 Original
2020-11-06 15:00:53 3098browse

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.

How to determine whether a method in php exists

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn