|  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.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: anrdaemon at freemail dot ru
New email:
PHP Version: OS:


 [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-2018 The PHP Group
All rights reserved.
Last updated: Fri Dec 14 05:01:25 2018 UTC