Using the Magic method __class__ in PHP to get the class name related operations

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.