|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74585 chroot doesn't change __DIR__ constant
Submitted: 2017-05-12 19:28 UTC Modified: 2017-05-12 20:40 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: joomla at itronic dot at Assigned:
Status: Open Package: CGI/CLI related
PHP Version: 7.0.19 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: joomla at itronic dot at
New email:
PHP Version: OS:


 [2017-05-12 19:28 UTC] joomla at itronic dot at
If you change the root dir, the __DIR__ doesn't reflect the change. Maybe this effects other Magic constants.

Test script:
echo __DIR__;

Expected result:
__DIR__ should have the correct path.

Actual result:
The old path


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-12 20:29 UTC]
-Status: Open +Status: Not a bug
 [2017-05-12 20:29 UTC]
> __DIR__	The directory of the file.

It is not affected by chdir(), as expected, maybe you're looking for getcwd().
 [2017-05-12 20:40 UTC]
-Status: Not a bug +Status: Open
 [2017-05-12 20:40 UTC]
It's chroot, not chdir. The idea is that __DIR__ and friends should be updated to reflect the new path to the file after the chroot(2) call. Which is not necessarily possible (eg, file is outside the new root) so I don't know if anything can/should be done about it anyways.

echo __FILE__; // originally /path/to/file.php
echo __FILE__; // now /to/file.php
 [2017-05-12 21:16 UTC] joomla at itronic dot at
In my current use case I execute chroot in auto_prepend_file so I'm not sure when the __FILE__ constant is filled.

The reason for this is to execute customer cronjobs in a jail. And most frameworks uses __DIR__ to require other files like autoload.php...

In this case it seams that the executed file get loaded (and __DIR__ is set) before the auto_prepend_file is executed. I'm not sure if it would be possible that at least this can be fixed.
 [2017-05-12 22:48 UTC] spam2 at rhsoft dot net
No -__DIR__ reflects the physical directory where the current file is stored and is practically the same as __FILE__ without the basename - it is known at compile time and any change after that would break half of the world in existing code
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 16 03:01:23 2021 UTC