|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #72738 realpath() expands junction points
Submitted: 2016-08-02 19:31 UTC Modified: 2020-11-18 17:15 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: cmb (profile)
Status: Closed 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.
 [2020-11-16 13:22 UTC]
-Assigned To: +Assigned To: cmb
 [2020-11-16 13:22 UTC]
I had a closer look, but I'm not really sure how it is
supposed to work.  In bug #72642 pajoye said:

> This function solves symbolic link only, not junction, mount
> point or hard link.

However, that is not correct; actually, exactly one level of links
is resolved on Windows.

pajoye continues:

> and it is on purpose and by design. The same applies to other
> platforms with hard links for example.

I don't know how other platforms deal with this.  Apparently,
POSIX is not clear about this[1], but the ln man page[2] mentions
that hardlinked directories are usually not supported at all.

Anyhow, symlinked directories are not recursively resolved on
Windows (only one level like for hardlinked directories), and that
would be a bug.

[1] <>
[2] <>
 [2020-11-18 17:15 UTC]
-Type: Bug +Type: Documentation Problem
 [2020-11-18 17:15 UTC]
I talked with other members of the PHPonWindows team, and our
stance is to leave that as is.  The behavior should be documented,
of course.
 [2020-11-19 13:30 UTC]
-Status: Verified +Status: Closed
 [2020-11-19 13:30 UTC]
Automatic comment on behalf of cmb
Log: Fix #72738: realpath() expands junction points
 [2020-11-20 20:00 UTC]
Automatic comment on behalf of mumumu
Log: Fix #72738: realpath() expands junction points
 [2020-12-30 11:58 UTC]
Automatic comment on behalf of mumumu
Log: Fix #72738: realpath() expands junction points
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 13:01:29 2024 UTC