Bug #73797 [Ana]: __DIR__ !== getcwd() when starting php with a file in a junction

From: Date: Tue, 07 Feb 2017 15:08:28 +0000
Subject: Bug #73797 [Ana]: __DIR__ !== getcwd() when starting php with a file in a junction
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207212@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73797&edit=1 ID: 73797 Updated by: nikic@php.net Reported by: anrdaemon at freemail dot ru Summary: __DIR__ !== getcwd() when starting php with a file in a junction Status: Analyzed Type: Bug Package: Filesystem function related Operating System: Windows PHP Version: 7.1.0 Block user comment: N Private report: N New Comment: __FILE__ and __DIR__ being symlink-resolved is documented on http://php.net/manual/en/language.constants.predefined.php. getcwd() not being symlink-resolved is not explicitly mentioned, as this is the default assumption. To clarify your request, you wish the documentation to explicitly mention that getcwd() is not symlink-resolved, is that correct? Note that the assumption of __DIR__ == getcwd() is meaningless regardless of symlink-resolution, because __DIR__ refers to the directory the current file resides in, which has *nothing* to do with the CWD. Previous Comments: ------------------------------------------------------------------------ [2017-02-07 15:01:07] anrdaemon at freemail dot ru To clarify, https://github.com/composer/composer/pull/5985/files#diff-a5d43a2d9fdda6d891a6fabcc622d898L99 ------------------------------------------------------------------------ [2017-02-07 14:58:02] anrdaemon at freemail dot ru If you think this behavior is by design, it may be worth explicitly mentioning this point in documentation. I've seen such assumption (getcwd() == __DIR__) used in Composer code. ------------------------------------------------------------------------ [2017-02-06 11:58:27] requinix@php.net I've never seen anyone modify it to look like Linux. The repro is to start php.exe on a file that resides in a junction-ed directory. But I don't know whether this is a bug: __DIR__ reflects the actual path to the file (prevents symlink-type exploits) and getcwd() reflects the directory cmd was using when php.exe was started. I guess the latter could be modified to reflect the former? But you shouldn't rely on __DIR__ == getcwd() anyways in case there's unexpected code that changes the working directory, as can happen when shutdown handlers are involved. Is __DIR__ != getcwd() actually a problem for you (how so?) or did you just notice this was the case? If it is a problem then you simply chdir(__DIR__)? ------------------------------------------------------------------------ [2017-02-06 11:45:50] anrdaemon at freemail dot ru You're not familiar with standard Windows CMD? SET PROMPT=[%USERNAME%@%COMPUTERNAME% $P]$_$G$S ------------------------------------------------------------------------ [2017-02-05 10:17:14] requinix@php.net I'm not familiar with that "SYSTEM@DAEMON-V7" CLI. What is it? What if you try your steps from the regular cmd.exe? ------------------------------------------------------------------------ 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=73797 -- Edit this bug report at https://bugs.php.net/bug.php?id=73797&edit=1

« previous php.bugs (#207212) next »