The purpose of this constant is to keep the file path pattern compatible on different operating systems. Mainly to
distinguish between Linux and Windows operating systems. On Windows, the directory separator is
'\', although Windows
'/' as its directory separator which then makes you think, perhaps, by converting all directory
'/' is sufficient to make the file path pattern compatible on both operating systems.
require PATH . D . 'foo' . D . 'bar' . D . 'baz.php';
The main purpose of prioritizing the
D constant over a
'/' string literal when making a file path is to keep the
process of manipulating a file path string consistent on all operating systems. We never know what type of directory
separator will be passed from the
__DIR__ constant so the below manipulation will most likely give different results
on different operating systems.
// Assume that `__DIR__` is `'./srv/http/engine'` on Linux // and `'C:\Users\Taufik\Server\http\engine'` on Windows $file = __DIR__ . '/kernel/anemone.php'; // On Linux, this will return `'./srv/http/application/kernel/anemone.php'` as you would expect // On Windows, this will return `'C:\Users\Taufik\Server\http\engine/kernel/anemone.php'` echo strtr($file, ['/engine/' => '/application/']);