Apart from regular constants, PHP also has a separate constant type - magic constants. We can sum up their difference as follows:
- Magic constants can’t be defined by us, we only can use the exsisting ones.
- Magic constant is wrapped in double underscores
- The magic is that such constants have the same value only when used in the same part of the program.
The last point may sound weird to you. It doesn’t sound like a constant, right? They may not be permanent, but the way they change is strictly regulated and it doesn’t cause us any troubles. Examples of such constants are:
__LINE__— contains the current line of the file in which this constant is used
__FILE__— path to the current file
__DIR__— path to the directory of the current file
Output the path to the current directory using a magic constant.
Magic constant — a special constant predefined in the PHP core; it’s value depends on the context
Please sign in with your GitHub account, this is necessary to track the progress of the lessons. If you do not have an account yet, now is the time to create an account on Github.