Req #48659 [Com]: dirname() to accept path level to return

From: Date: Thu, 01 May 2014 10:37:15 +0000
Subject: Req #48659 [Com]: dirname() to accept path level to return
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185546@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48659&edit=1

 ID:                 48659
 Comment by:         ninzya at inbox dot lv
 Reported by:        ninzya at inbox dot lv
 Summary:            dirname() to accept path level to return
 Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Filesystem function related
 Operating System:   Irrelevant
 PHP Version:        Any
 Block user comment: N
 Private report:     N

 New Comment:

Yep, agree. That's what I do already. Just thought maybe implementing this feature in dirname()
natively would make things better.

Thanks anyway. Not a critical problem!


Previous Comments:
------------------------------------------------------------------------
[2014-05-01 10:30:14] ajf at ajf dot me

Oops, you're right. However, if you want to make it strip multiple levels, you can simply apply
the function multiple times, or write a function to apply it so:

function dirname_multilevel($path, $level = 1) {
    return $level ? dirname_mutilevel(dirname($path), $level - 1) : $path;
}

------------------------------------------------------------------------
[2014-05-01 10:21:57] ninzya at inbox dot lv

Quote from dirname() docs:

dirname() operates naively on the input string, and is not aware of the actual filesystem, or path
components such as "..".

Therefore, dirname( "a/b/c/.." ) will yield "a/b/c" which is not what I want.

>> It's completely unnecessary
Wouldn't say that it is COMPLETELY unnecessary. Otherwise, why do we have dirname() in first
place? We have "..", right?

One of valid use cases is to keep paths without ".." bloat.

------------------------------------------------------------------------
[2012-07-13 15:56:29] ajfweb at googlemail dot com

This is ancient, but this should be closed. It's completely unnecessary, .. 
exists.

------------------------------------------------------------------------
[2009-06-23 10:47:18] ninzya at inbox dot lv

Description:
------------
It would be great if dirname() function had a second parameter, let's say - uint $level, which
would mean "how many path levels to strip off". By default this parameter could be set to
1 to not to break the backwards compatibility.

Reproduce code:
---------------
<?php

$path ='/var/www/localhost/public_html/tpl/';

echo dirname( $path);// /var/www/localhost/public_html
echo dirname( $path, 2);// /var/www/localhost
echo dirname( $path, 3);// /var/www/
echo dirname( $path, 4);// /var
echo dirname( $path, 5);// .
echo dirname( $path, 6);// .

?>

Expected result:
----------------
Expect this feature to be implemented

Actual result:
--------------
-


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=48659&edit=1


Thread (6 messages)

« previous php.bugs (#185546) next »