The Magic method __class__ to get the class name related operations are often encountered in PHP, this article will explain its related operations.
Tutorial on using the Magic method __class__ to get the class name in PHP
Official documents are as follows
The name of the __class__ class (PHP 4.3.0 new addition). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). In PHP 4, this value is always in lowercase letters. The class name includes its declared action area (for example, Foo\bar). Note from PHP 5.4 CLASS to trait
Also works. When used in the trait method, class is the name of the classes that call the trait method.
If you want to get the name of a scope that does not contain classes or the scope of a class, you need the following two functions
String basename (String $path [, String $suffix])
Gives a string containing a full path to a file, which returns the directory name after removing the file name.
String DirName (String $path)
Give a string containing a full path to a file, this function returns the base file name.
class contains the name of the scope
Echo __class__;
The name of the class scope
echo dirname (__class__);
Class does not contain a name for the scope
Echo basename (__class__);
This article explains the use of the Magic method __class__ in PHP to get the class name of the relevant operations, more relevant content please focus on PHP Chinese web.
Related recommendations:
PHP code to achieve more than 12,306 votes query, price query function
How to get the user's OpenID and basic information via PHP
Introduction to PHP quick Export table data related tutorials