php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32162 dirname returning \ for root entries
Submitted: 2005-03-02 08:21 UTC Modified: 2005-03-20 18:11 UTC
Votes:6
Avg. Score:4.0 ± 0.6
Reproduced:6 of 6 (100.0%)
Same Version:0 (0.0%)
Same OS:4 (66.7%)
From: paul at wavebreaks dot com Assigned:
Status: No Feedback Package: Directory function related
PHP Version: 5.0.3 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2005-03-02 08:21 UTC] paul at wavebreaks dot com
Description:
------------
This is probably the same or related to http://bugs.php.net/bug.php?id=25450 and http://bugs.php.net/bug.php?id=18710 but since they are for Win 2k and/or closed, I thought the best bet was to open a new one.

When a path-like-string is passed to dirname, if, and only if, the last entity (file, dir) is on the root (ie: only one / in the string) then dirname returns a backslash instead of a forward slash.

There doesn't appear to be a config to tell PHP which part seperator to use, thus the dirname function is pointlessly broken unless you can guarentee it will never be given a root level entry.

This, also, breaks your example in the documentation for header() for Location: header types.

Reproduce code:
---------------
print (dirname('/foo')."\n");
print (dirname('/foo/bar')."\n");

Expected result:
----------------
/
/foo

Actual result:
--------------
\
/foo

You might argue it's not a bug since Windows is meant to handle both types of path seperator, but a URI does not, and this is you main audience. 

This issue has been around for way past way too long.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-06 16:26 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-03-20 18:11 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2005-05-05 14:01 UTC] loom at nons dot de
still this problem with PHP 5.0.4 WinXP SP2

Details:
PHP Version 5.0.4
System 	Windows NT LOOM-M 5.1 build 2600
Build Date 	Mar 31 2005 02:44:34
Configure Command 	cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"
Server API 	Apache
Virtual Directory Support 	enabled
Configuration File (php.ini) Path 	C:\WINDOWS\php.ini
PHP API 	20031224
PHP Extension 	20041030
Zend Extension 	220040412
Debug Build 	no
Thread Safety 	enabled

apache
Apache for Windows 95/NT

Apache Version 	Apache/1.3.29 (Win32) PHP/5.0.4
Apache Release 	10329100
Apache API Version 	19990320
 [2007-08-15 23:36 UTC] ich at der-bigga dot de
This problem still exists with version 5.2.3 (OS: Windows XP SP 2, German) like loom at nons dot de mentioned. The string dirname() return should always include the same directory separator character as the string provided. So if I use the following:
print (dirname('/foo')."\n");
the function should return '/' because I used the slash as directory seperator character, too.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC