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

From: Date: Tue, 07 Feb 2017 14:58:06 +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-207210@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: 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. Previous Comments: ------------------------------------------------------------------------ [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? ------------------------------------------------------------------------ [2017-02-05 10:00:03] anrdaemon at freemail dot ru [SYSTEM@DAEMON-V7 C:\] > mklink /J "%TEMP%\test.dir" "C:\Documents and Settings\Public\Desktop" соединение создано для C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir <<===>> C:\Documents and Settings\Public\Desktop [SYSTEM@DAEMON-V7 C:\] > cd "%TEMP%\test.dir" [SYSTEM@DAEMON-V7 C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir] > echo ^<^?php print __DIR__ . ^"\n^"; print getcwd() . ^"\n^"; > > test.php [SYSTEM@DAEMON-V7 C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir] > C:\php\php.exe -f test.php C:\Documents and Settings\Public\Desktop C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir [SYSTEM@DAEMON-V7 C:\Users\ANRDAE~1\AppData\Local\Temp\test.dir] > cd \ && del "%TEMP%\test.dir\test.php" && rd > "%TEMP%\test.dir" [SYSTEM@DAEMON-V7 C:\] > ------------------------------------------------------------------------ [2017-02-05 08:51:04] requinix@php.net "Exactly as provided"? Okay. C:\>mklink /J "%TEMP%\test.dir" "C:\Documents and Settings\Public\Desktop" Junction created for C:\Users\*\AppData\Local\Temp\test.dir <<===>> C:\Documents and Settings\Public\Desktop C:\>cd "%TEMP%\test.dir" C:\Users\*\AppData\Local\Temp\test.dir>echo ^<^?php print __DIR__ . ^"\n^"; print getcwd() . ^"\n^"; > test.php Access is denied. C:\Users\*\AppData\Local\Temp\test.dir>C:\php\php.exe -f test.php The system cannot find the path specified. Now it's your turn: What is the output when YOU run the steps exactly as provided? ------------------------------------------------------------------------ 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 (#207210) next »