|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35064 Adding an optional $directorySeparator parameter to realpath()
Submitted: 2005-11-02 10:24 UTC Modified: 2021-07-19 17:44 UTC
Avg. Score:4.0 ± 1.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: pecoes at gmail dot com Assigned: cmb (profile)
Status: Wont fix Package: Filesystem function related
PHP Version: 5.0.5 OS: WinXP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-11-02 10:24 UTC] pecoes at gmail dot com
Correct me if I'm wrong, but there doesn't seem to be a single PHP-function that requires backslashes in pathnames on a Windows-box. They all work happily with forward slashes. Personally, I have stopped using backslashes altogether, but there's a single function that's always a thorn in my side: realpath(). That frequently leads to ugly work-arounds such as this:

$path = str_replace('\\', '/', realpath($rawpath));

So I'd like to suggest adding an optional $directorySeparator parameter, that would default to the DIRECTORY_SEPARATOR constant:

$path = realpath($rawpath, '/');

(Actually I'd prefer $directorySeparator to default to '/', but letting it default to DIRECTORY_SEPARATOR will cause no incompatibilities with anyone's existing code...)

Hope that makes sense to you :0)

Reproduce code:
see text

Expected result:
see text

Actual result:
see text


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 23:16 UTC]
-Package: Feature/Change Request +Package: Filesystem function related
 [2021-07-19 17:44 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-07-19 17:44 UTC]
> Hope that makes sense to you :0)

No, it does not.  realpath() is supposed to "return the
canonicalized absolute pathname", and the canonical directory
separator on Windows is a backslash.

If you still think this would be a useful feature, please pursue
the RFC process[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 03:01:31 2024 UTC