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

How to determine whether a method in php exists

王林
Release: 2023-03-07 12:56:01
Original
3223 people have browsed it

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方法!';
}
Copy after login

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属性!';
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template