PHP Basic Tutorial
MySQL Connection
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 |
---|---|
__LINE__ |
Current line number |
__FILE__ |
Full path and filename of the file |
__DIR__ |
Directory of the file |
__FUNCTION__ |
Function name |
__METHOD__ |
Class method name |
__NAMESPACE__ |
Current namespace |
__TRAIT__ |
Trait name (PHP 5.4+) |
ClassName::class |
Returns the name of the specified class and the name of the namespace, if any. |
Try it yourself
2. __FILE__
3. __DIR__
4. __FUNCTION__
Try it yourself
5. __CLASS__
__CLASS__
includes the namespace in its value (if applicable).Try it yourself
6. __METHOD__
Try it yourself
7. __NAMESPACE__
Try it yourself
8. __TRAIT__ (Introduced in PHP 5.4)
Try it yourself
9. ClassName::class
Try it yourself