php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51952 __FILE__ and dirname() are returning wrong pathes when working with junctions
Submitted: 2010-05-31 01:39 UTC Modified: 2010-05-31 02:36 UTC
From: whistl0r+phpbug at googlemail dot com Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 5.2.13 OS: Windows Vista/7
Private report: No CVE-ID: None
 [2010-05-31 01:39 UTC] whistl0r+phpbug at googlemail dot com
Description:
------------
Consister the following setup:

You keep your source code in "C:\Repositories\example.org\trunk".
You just point your DOCUMENT_ROOT to that folder via symlink/junction:

httpd.conf:
[...]
DOCUMENT_ROOT "C:\Sites\example.org\htdocs"
[...]

C:\Sites\example.org>dir
 Volume in drive D is System
 Volume Serial Number is E49D-A2E7

 Directory of C:\Sites\example.org

2010-05-31  01:08    <DIR>          .
2010-05-31  01:08    <DIR>          ..
2010-05-31  01:08    <JUNCTION>     htdocs [C:\Repositories\example.org\trunk]

You now run the script "C:\Sites\example.org\htdocs\test.php".

Test script:
---------------
<?php
echo 'File: ' . __FILE__ . PHP_EOL;
echo 'Dir: ' . dirname(__FILE__) . PHP_EOL;

Expected result:
----------------
File: C:\Repositories\example.org\trunk\test.php
Dir: C:\Repositories\example.org\trunk

Actual result:
--------------
File: C:\Sites\example.org\htdocs\test.php
Dir: C:\Sites\example.org\htdocs

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-31 01:44 UTC] whistl0r+phpbug at googlemail dot com
I found this inconsistent behavior, after upgrading to PHP 5.3, because a required 
once call (required_once realpath(dirname(__FILE__) . '/../configs/main.php');) 
failed.

It failed because PHP 5.3 resolves the symlinks.

I checked the documentation and it says that this is the wanted behavior.

So it seems like, because it nothing new in PHP 5.3, that it must be a bug in PHP 
5.2.
 [2010-05-31 02:36 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-05-31 02:36 UTC] pajoye@php.net
Windows was the only platform where it did not resolve it. The reason was that 5.2 did not support symlink on windows (or junctions) resolutions.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Nov 28 09:01:23 2020 UTC