Get the App
SLTechnology News&Howtos  ›  Development  › 

How does php check whether the method of a class exists

Shulou Source: shulou.com Published: 2022-06-03 09:50:17 10月31日 Update

This article is about how php checks for the existence of methods of a class. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In PHP, you can use the method_exists () function to check whether the class's method exists in the specified object, with the syntax "method_exists ($object,$method_name)"; if so, return true, otherwise return false.

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

Php checks for the existence of methods in the class. You can use the method_exists () function.

Method_exists-checks whether the method of the class exists, and that the method of the class exists in the specified object.

Syntax:

Method_exists ($object,$method_name)

Parameters:

Object: object example or class name.

Method_name: method name.

Return value: returns true if the method referred to by method_name is defined in the object class referred to by object, otherwise it returns false.

Example:

Output result:

Bool (true) Thank you for your reading! This is the end of this article on "how to check the existence of class methods in php". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Methods checks functions objects contents references more examples articles grammars good practical parameters tutorials articles environments computers see knowledge class names Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Shulou Tech Info NVidia Linux