php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36956 dirname returns \ for root /
Submitted: 2006-04-03 13:33 UTC Modified: 2007-08-20 12:21 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: e dot vandeoudeweetering at marcanti dot esprit-sg dot Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.1.4 OS: Windows 2000 (5.00.2195) SP4
Private report: No CVE-ID: None
 [2006-04-03 13:33 UTC] e dot vandeoudeweetering at marcanti dot esprit-sg dot
Description:
------------
When using the function dirname, \ is returned for the root directory /

This is what the documentation says:
//after PHP 4.3.0
dirname('c:/'); // returns 'c:'

Reproduce code:
---------------
print dirname('/');
print dirname('C:/');
print dirname('C:\\'); //this function works

Expected result:
----------------
/
C:
C:\

Actual result:
--------------
\
C:\
C:\

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-04 11:58 UTC] e dot vandeoudeweetering at marcanti dot esprit-sg dot
I did check the following documentation:
  http://nl3.php.net/manual/en/function.dirname.php

dirname('c:/'); 
it returns c:\ (notice the backslash)
the documentation says it should return c:

suggest the following 7 examles:

$dir = 'C:\\Temp';
print "$dir\t\t: ".dirname($dir).'\\'.basename($dir)."\n";
$dir = 'C:/Temp';
print "$dir\t\t: ".dirname($dir).'/'.basename($dir)."\n";
$dir = 'C:\\';
print "$dir\t\t: ".dirname($dir).'\\'.basename($dir)."\n";
$dir = 'C:/';
print "$dir\t\t: ".dirname($dir).'/'.basename($dir)."\n";
$dir = '\\\\server\\share';
print "$dir\t: ".dirname($dir).'\\'.basename($dir)."\n";
$dir = '//server/share';
print "$dir\t: ".dirname($dir).'/'.basename($dir)."\n";
$dir = '/usr/local';
print "$dir\t: ".dirname($dir).'/'.basename($dir)."\n";

The following output is generated:

C:\Temp         : C:\\Temp
C:/Temp         : C:\/Temp
C:\             : C:\\C:
C:/             : C:\/C:
\\server\share  : \\server\share
//server/share  : //server/share
/usr/local      : /usr/local

The following output is expected:

C:\Temp         : C:\Temp
C:/Temp         : C:/Temp
C:\             : C:\
C:/             : C:/
\\server\share  : \\server\share
//server/share  : //server/share
/usr/local      : /usr/local

As you see something is wrong!
 [2006-04-10 12:01 UTC] sniper@php.net
Please try using this CVS snapshot:

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


 [2006-04-26 11:13 UTC] e dot vandeoudeweetering at marcanti dot esprit-sg dot
I used:

C:\phptemp>php -v
PHP 5.1.3RC4-dev (cli) (built: Apr 26 2006 12:19:43)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

With the same result as before:
C:\phptemp>test.php
C:\Temp         : C:\\Temp
C:/Temp         : C:\/Temp
C:\             : C:\\C:
C:/             : C:\/C:
\\server\share  : \\server\share
//server/share  : //server/share
/usr/local      : /usr/local
 [2006-05-22 06:45 UTC] e dot vandeoudeweetering at marcanti dot esprit-sg dot
I used the latest release of php:

C:\phptemp>php -v
PHP 5.1.4 (cli) (built: May  4 2006 10:35:22)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

Still the bad results:

C:\phptemp>test.php
C:\Temp         : C:\\Temp
C:/Temp         : C:\/Temp
C:\             : C:\\C:
C:/             : C:\/C:
\\server\share  : \\server\share
//server/share  : //server/share
/usr/local      : /usr/local
 [2006-08-29 10:12 UTC] e dot vandeoudeweetering at marcanti dot esprit-sg dot
Again the same results, this time with php:

C:\>php -v
PHP 5.1.6 (cli) (built: Aug 23 2006 16:35:53)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

Results:
C:\>test.php
C:\Temp         : C:\\Temp
C:/Temp         : C:\/Temp
C:\             : C:\\C:
C:/             : C:\/C:
\\server\share  : \\server\share
//server/share  : //server/share
/usr/local      : /usr/local
 [2006-10-18 21:39 UTC] tony2001@php.net
Reclassified as docu problem.
 [2007-08-20 12:21 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

<?php
dirname('c:/x'); // returns 'c:\'
dirname('c:/Temp/x'); // returns 'c:/Temp'
dirname('/x'); // returns '\'
?>

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 03:01:33 2025 UTC