Magic Constants
Learn about the magic constants and their usage.
We'll cover the following
In addition to magic methods, the PHP language offers several magic constants.
For example, we may use the magic constant __CLASS__
in order to get the name of the class in which it resides.
Note: Magic constants are written in uppercase letters and prefixed and suffixed with two underlines.
The __CLASS__
magic constant
Let’s take a look at the following example in which we use the __CLASS__
magic constant in the getter method:
Get hands-on with 1400+ tech skills courses.