How to check if a class method exists in php

青灯夜游
Release: 2023-03-13 06:14:01
Original
2033 people have browsed it

In PHP, you can use the method_exists() function to check whether a class method exists. This function can check whether a class method exists in the specified object. The syntax is "method_exists($object,$method_name)"; if Returns true if it exists, otherwise returns false.

How to check if a class method exists in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php check whether the class method exists You can use the method_exists() function.

method_exists - Check whether the method of the class exists, check whether the method of the class exists in the specified object.

Syntax:

method_exists($object,$method_name)
Copy after login

Parameters:

  • object: object example or class name.

  • method_name: method name.

Return value: If the method pointed by method_name has been defined in the object class pointed by object, then return true, otherwise return false.

Example:

Copy after login

Output result:

bool(true)
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to check if 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!