How to determine whether a class method exists in php

王林
Release: 2023-03-03 14:56:02
Original
5008 people have browsed it

php method to determine whether a class method exists: You can use the method_exists() function to determine. The specific usage method is: [method_exists($directory,'read')]. The method_exists() function checks whether a class method exists in the specified object.

How to determine whether a class method exists in php

Function definition:

(Recommended tutorial:php graphic tutorial)

method_exists( ) function checks whether a class method exists in the specified object. 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.

Function syntax:

bool method_exists ( mixed $object , string $method_name )
Copy after login

(Video tutorial recommendation:php video tutorial)

Code implementation:

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

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!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!