Originally published on zero2php.dev — part of the Zero to PHP course. View this lesson on the original site.

What “magic” means here

Magic constants change depending on where PHP is executing:

  • __LINE__ — current line number
  • __FILE__ — full path of the current file
  • __DIR__ — directory of the current file

Example

<?php

declare(strict_types=1);

echo __FILE__, "\n";
echo __DIR__, "\n";

When this helps

Useful for debugging paths while you learn includes and autoloading later.

From Zero to PHP — PHP foundations: environment, syntax, and values