|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72738 realpath() expands junction points
Submitted: 2016-08-02 19:31 UTC Modified: 2016-08-02 22:29 UTC
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: anrdaemon at freemail dot ru Assigned:
Status: Verified Package: Filesystem function related
PHP Version: 7.1.0beta1 OS: Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-08-02 19:31 UTC] anrdaemon at freemail dot ru
On Windows, realpath() expands the directory junction points.
According to an apparently authoritative assesment of in the , this shouldn't happen.

Test script:

$rootdir = substr(getenv('SystemRoot'), 0, 3);
$tmpdir = getenv('TEMP');
shell_exec("mklink /J \"{$rootdir}home\" \"{$rootdir}Users\"");
shell_exec("mklink /J \"{$tmpdir}\\test.dir\" \"{$rootdir}home\\Public\\Desktop\"");
$file = "{$tmpdir}\\test.dir\\desktop.ini";
$rfile1 = realpath($file);
$rfile2 = realpath($rfile1);
printf("orig.file name: %s\n", $file);
printf("realpath(name): %s (%s)\n", $rfile1, $file == $rfile1 ? 'Ok' : 'fail');
printf("THE real name:  %s (%s)\n", $rfile2, $file == $rfile2 ? 'Ok' : 'fail');


Expected result:
According to, expansion shouldn't happen, and all paths must be the same == the original path.

Actual result:
All paths are different. On each iteration, realpath() only expands a portion of nested junctions.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-02 22:29 UTC]
-Status: Open +Status: Verified
 [2016-08-02 22:29 UTC]
I can confirm this behavior. Obviously, the invariant

  realpath(realpath($x)) == realpath($x)

does not hold in this case.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 06:01:24 2020 UTC