Home  >  Article  >  Backend Development  >  How to get the current method name in php

How to get the current method name in php

藏色散人
藏色散人Original
2022-11-01 09:38:211791browse

In PHP, you can get the current method name through "__METHOD__", using syntax such as "get_class_methods(class name);", where "__METHOD__" is a new magic constant after PHP5, which represents a class grammar. The name.

How to get the current method name in php

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

php How to get the current method name?

PHP Gets the current class name and method name

  • __CLASS__ Gets the current class name

  • __FUNCTION__ Current function name (confirm)

  • __METHOD__ Current method name (bankcard::confirm)

__FUNCTION__ Function name (PHP 4.3. 0 new additions). Since PHP 5 this constant returns the name of the function as it was defined (case sensitive). In PHP 4 this value is always lowercase.

__CLASS__ The name of the class (newly added in PHP 4.3.0). Since PHP 5 this constant returns the name of the class when it was defined (case sensitive). In PHP 4 this value is always lowercase.

__METHOD__ The method name of the class (newly added in PHP 5.0.0). Returns the name of the method as it was defined (case-sensitive).

Note: These constants are preceded and followed by two underscores.

get_class(class name);//取得当前语句所在类的类名
get_class_methods(class name);//取得class name 类的所有的方法名,并且组成一个数组
get_class_vars(class name);//取得class name 类的所有的变亮名,并组成一个数组

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to get the current method name 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