search
HomeBackend DevelopmentPHP ProblemHow to get the method name of the current class in php

The way php gets the method name of the current class is to use the magic constant __METHOD__ to get it, for example [function test() {echo 'function name:' . __METHOD__;}].

How to get the method name of the current class in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

php provides us with __FILE__, __DIR__, __LINE__, __CLASS__, __NAMESPACE__, __METHOD__, __FUNCTION__ and other magic variables, among which:

__FILE__: Returns the full path and file name of the file.

__DIR__: Returns the directory of the file.

__LINE__: Returns the line number of the current file.

__CLASS__: Returns the class name.

__NAMESPACE__: Returns the name of the current namespace.

__METHOD__: Returns the method name of the class.

__FUNCTION__: Returns the current function name.

Let’s take a look at the __METHOD__ magic constant.

It represents 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).

Example:

<?php
function test() {
    echo  &#39;函数名为:&#39; . __METHOD__ ;
}
test();
?>

Output result:

函数名为:test

Related video tutorial sharing: php video tutorial

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),