Magic constants are the predefined constants in PHP which get changed on the basis of their use. They start with double underscore (__) and ends with double underscore.
They are similar to other predefined constants but as they change their values with the context, they are called magic constants.
There are eight magical constants defined in the below table. They are case-insensitive.
||Represents current line number where it is used.
||Represents full path and file name of the file. If it is used inside an include, name of included file is returned.
||Represents full directory path of the file. Equivalent to dirname(__file__). It does not have a trailing slash unless it is a root directory. It also resolves symbolic link.
||Represents the function name where it is used. If it is used outside of any function, then it will return blank.
||Represents the class name where it is used. If it is used outside of any function, then it will return blank.
||Represents the trait name where it is used. If it is used outside of any function, then it will return blank. It includes namespace it was declared in.
||Represents the name of the class method where it is used. The method name is returned as it was declared.
||Represents the name of the current namespace.
Let's see an example for each of the above magical constants.
File Name: magic.php