php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21222 problem with dirname
Submitted: 2002-12-27 15:24 UTC Modified: 2002-12-27 19:28 UTC
From: Beater at orgalan dot de Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 4.3.0 OS: Win2k
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Beater at orgalan dot de
New email:
PHP Version: OS:

 

 [2002-12-27 15:24 UTC] Beater at orgalan dot de
Hi there,

<?php
echo $_SERVER['REQUEST_URI'] . '<br>';
echo '"' . dirname($_SERVER['REQUEST_URI']) . '"';
?>

produces following output...
/test.php
"\"

Instead of the output above, i expected
/test.php
""

Can someone confirm this?

Daniel

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-27 15:27 UTC] rasmus@php.net
Your expectation is simply wrong.  dirname() is documented to return the directory component of a pathname you feed it.  You fed it /test.php and it gave you back / (or the Windows equivalent thereof) as expected.`
 [2002-12-27 15:46 UTC] michiwalter at gmx dot de
That reasoning doesn't quite go along with what the documentation says, IMHO:

(quoted from http://www.php.net/dirname)
"[...]Essentially, this means that if there are no slashes in path , a dot ('.') is returned, indicating the current directory. Otherwise, the returned string is path with any trailing /component removed.[...]"

So for the input '/test.php', the first case (no slashes in path) obviously doesn't apply, since there is a slash contained in the path in question.

Now, the second case states that the returned string is the path ('/test.php') with any trailing /component (in this case '/test.php') removed, i.e. simply ''.

So there seems to be some kind of contradiction between the manual and what you said, could your elaborate on that, please? Apologies if I'm missing the point,

Michael

PS: Even if the behaviour was changed to return '/' instead of an empty string, the transformation of '/' to the default directory separator should still be officially documented (and not in the user comments).
 [2002-12-27 15:49 UTC] rasmus@php.net
No, the trailing / the docs talk about are cases where you actually have a trailing / in the source path.  eg. /some/path/
It does not mean that the trailing path of the returned string will be stripped.
 [2002-12-27 19:28 UTC] philip@php.net
See also:
http://bugs.php.net/bug.php?id=20895

Maybe someone with a clue (unlike me) can document this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 04:01:27 2024 UTC