PHP Basic Tutorial
MySQL Connection
PHP Advanced
PHP OOP
Magic constants are predefined constants that change based on their location in the code. Unlike regular constants, they do not have fixed values; instead, their values change depending on where they are used. Magic constants start and end with double underscores (__
), except for the ClassName::class constant.
Magic Constant |
Description |
---|---|
Current line number |
|
Full path and filename of the file |
|
Directory of the file |
|
Function name |
|
Class method name |
|
Current namespace |
|
Trait name (PHP 5.4+) |
|
Returns the name of the specified class and the name of the namespace, if any. |
Try it yourself
__CLASS__
includes the namespace in its value (if applicable).Try it yourself
Try it yourself
Try it yourself
Try it yourself
Try it yourself