Bug #74585 [Com]: chroot doesn't change __DIR__ constant
| From: | spam2 at rhsoft dot net | Date: | Fri, 12 May 2017 22:48:14 +0000 |
| Subject: | Bug #74585 [Com]: chroot doesn't change __DIR__ constant | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209094@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74585&edit=1
ID: 74585
Comment by: spam2 at rhsoft dot net
Reported by: joomla at itronic dot at
Summary: chroot doesn't change __DIR__ constant
Status: Open
Type: Bug
Package: CGI/CLI related
Operating System: Linux
PHP Version: 7.0.19
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2017-05-12 21:16:14] 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 20:40:51] requinix@php.net
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
chroot("/path");
echo __FILE__; // now /to/file.php
------------------------------------------------------------------------
[2017-05-12 20:29:18] dm@php.net
> __DIR__ The directory of the file.
It is not affected by chdir(), as expected, maybe you're looking for getcwd().
------------------------------------------------------------------------
[2017-05-12 19:28:15] joomla at itronic dot at
Description:
------------
If you change the root dir, the __DIR__ doesn't reflect the change. Maybe this effects other
Magic constants.
Test script:
---------------
chroot('/tmp');
echo __DIR__;
Expected result:
----------------
__DIR__ should have the correct path.
Actual result:
--------------
The old path
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74585&edit=1