PHP TutorialLesson 14Free preview
PHP Magic Constants
This lesson is part of PHP · All levels
Summary
Magic constants are special constants whose values are automatically determined by PHP according to where they are written. The characteristic is that it is always preceded and terminated by two double bottom lines, for example __FILE__ or __LINE__. This feature is useful for debugging, logging, and dynamically building directory paths.
Key points
- Magic constants are written with two double bottom lines on the left and right
- __FILE__ displays the file name, __LINE__ displays the line number
- __DIR__ displays the directory where the files are located
- Magic constants are automatically replaced by PHP values according to their context
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.