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

How to determine whether a class method exists in php

王林
王林Original
2020-08-01 13:38:593984browse

php method to determine whether a class method exists: You can use the method_exists() function to determine. Function syntax: [method_exists(mixed $object,string $method_name)], if the method has been defined in the object class, it returns TRUE.

How to determine whether a class method exists in php

method_exists() checks whether the method of the class exists. If the method pointed to by method_name has been defined in the object class pointed to by object, then TRUE is returned, otherwise FALSE is returned.

(Recommended tutorial: php graphic tutorial)

Function syntax:

bool method_exists(mixed $object, string $method_name)

(Recommended video tutorial: php video tutorial)

Code implementation:

$directory=new Directory;
if(!method_exists($directory,'read')){
    echo '未定义read方法!';
}

The above is the detailed content of How to determine whether a class method exists in php. 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