Doc #74585 [Opn->Csd]: chroot doesn't change __DIR__ constant
| From: | git@php.net | Date: | Mon, 26 Apr 2021 16:46:53 +0000 |
| Subject: | Doc #74585 [Opn->Csd]: chroot doesn't change __DIR__ constant | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-18728@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
Updated by: git@php.net
Reported by: joomla at itronic dot at
Summary: chroot doesn't change __DIR__ constant
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: CGI/CLI related
Operating System: Linux
PHP Version: 7.0.19
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/625dc345dba34bd0e8f97b6fac4272a5e8359428
Log: Fix #74585: chroot doesn't change __DIR__ constant
Previous Comments:
------------------------------------------------------------------------
[2021-04-26 16:03:39] cmb@php.net
> 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.
That. It might be best to just clearly document that chroot()
doesn't affect __DIR__ and friends.
------------------------------------------------------------------------
[2017-05-12 22:48:12] 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
------------------------------------------------------------------------
[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().
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=74585
--
Edit this bug report at https://bugs.php.net/bug.php?id=74585&edit=1