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

From: Date: Tue, 07 Feb 2017 16:22:16 +0000
Subject: Bug #73797 [Com]: __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-207216@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 Comment by: anrdaemon at freemail dot ru 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: No, __DIR__ is not symlink-resolved on Windows. Not fully, at least. https://bugs.php.net/bug.php?id=72642 Also try the other script I provided. Very… special experience, I'd say. > type test.php <?php print getcwd() . "\n"; chdir(getcwd()); print getcwd() . "\n"; chdir(getcwd()); print getcwd() . "\n"; chdir(getcwd()); print getcwd() . "\n"; > test.php C:\Users\anrdaemon\AppData\Local\Temp\test.dir C:\Documents and Settings\Public\Desktop C:\Users\Public\Desktop C:\Users\Public\Desktop Previous Comments: ------------------------------------------------------------------------ [2017-02-07 15:08:27] nikic@php.net __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. ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ 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 (#207216) next »