Home » Php » php – dir manipulation(__DIR__) not working

php – dir manipulation(__DIR__) not working

Posted by: admin July 12, 2020 Leave a comment


the following behaves different in host:

echo 'DIR:' .__DIR__; // DIR:__DIR__

localhost:(works fine):

DIR:C:\Program Files\VertrigoServ\www

why this different output?

How to&Answers:

You need PHP 5.3 to use __DIR__

Manual page

On previous versions you may use dirname(__FILE__) instead


According to the PHP magic constants docs, the __DIR__ constant was added only in php 5.3.0. You’re probably using an older version in your “host” environment.



<? echo realpath(dirname(__DIR__)); ?>

Folder: localhost or root 🙂