php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70112 [RFE] Allow "dirname" to go up various time
Submitted: 2015-07-22 11:44 UTC Modified: 2015-07-24 21:47 UTC
From: remi@php.net Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 7.0.0beta1 OS: irrevelant
Private report: No CVE-ID: None
 [2015-07-22 11:44 UTC] remi@php.net
Description:
------------
We can find tons of code with
   $a = dirname(dirname($b));
   $c = dirname(dirname(dirname(__DIR__)));
   etc

Could be nice to be able to write
   $a = dirname($b, 2);
   $c = dirname(__DIR__, 3);
   etc

Proposal: Add a new "nb" optional parameter.

    Function [ <internal:standard> function dirname ] {

      - Parameters [2] {
        Parameter #0 [ <required> $path ]
        Parameter #1 [ <optional> $nb ]
      }
    }

As a minor, self-contained change, could probably target 7.0



Patches

0001-Fix-70112-RFE-Allow-dirname-to-go-up-various-times.patch (last revision 2015-07-25 14:59 UTC by remi@php.net)
0003-improve-loop-condition-to-avoid-hang-on-large-value.patch (last revision 2015-07-24 08:39 UTC by remi@php.net)
0002-rename-arg-nb-to-levels-frenchism.patch (last revision 2015-07-22 12:39 UTC by remi@php.net)
0001-Fix-70112-RFE-Allow-dirname-to-go-up-various-time.patch (last revision 2015-07-22 11:46 UTC by remi@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-22 11:46 UTC] remi@php.net
The following patch has been added/updated:

Patch Name: 0001-Fix-70112-RFE-Allow-dirname-to-go-up-various-time.patch
Revision:   1437565586
URL:        https://bugs.php.net/patch-display.php?bug=70112&patch=0001-Fix-70112-RFE-Allow-dirname-to-go-up-various-time.patch&revision=1437565586
 [2015-07-22 12:19 UTC] rowan dot collins at gmail dot com
Nice idea, but what on earth does "$nb" mean? I know parameter names of internal functions only really exist in documentation, and can be easily changed, but we might as well try to make it obvious. How about "$levels", or "$climb_levels", or spell out whatever "nb" stands for (I'm not being sarcastic, I'm genuinely not sure)?
 [2015-07-22 12:30 UTC] remi@php.net
nb stands for number... but false friend from French, sorry.
I fine with any other name, like "levels"
 [2015-07-22 12:39 UTC] remi@php.net
The following patch has been added/updated:

Patch Name: 0002-rename-arg-nb-to-levels-frenchism.patch
Revision:   1437568750
URL:        https://bugs.php.net/patch-display.php?bug=70112&patch=0002-rename-arg-nb-to-levels-frenchism.patch&revision=1437568750
 [2015-07-22 13:58 UTC] rowan dot collins at gmail dot com
Ah, that makes sense. English is particularly irrational when it comes to abbreviations, and tends to use fossilized Latinisms. We might say "no. 4", but probably not "what no. is that?", I guess because "no" is also a word...

Anyway, +1 on including this feature, though I'm not sure if it should be 7.0 or 7.1 at this point.
 [2015-07-24 08:39 UTC] remi@php.net
The following patch has been added/updated:

Patch Name: 0003-improve-loop-condition-to-avoid-hang-on-large-value.patch
Revision:   1437727140
URL:        https://bugs.php.net/patch-display.php?bug=70112&patch=0003-improve-loop-condition-to-avoid-hang-on-large-value.patch&revision=1437727140
 [2015-07-24 16:02 UTC] jpauli@php.net
I like it.

I'm +1.

It might be a little bit late to contribute it for 7.0, though it is very tiny and self contained.
This is the PHP7 RMs decision now.
 [2015-07-24 21:47 UTC] ab@php.net
Remi,

as it turns to be a bit more complicated right now, here were my 2 cents. The usage with 1 == levels is the common case. The current functionality should reside under an if branch, the new functionality including the levels < 1 and other error check should reside under an else branch. Does it sound logic?

Thanks

Anatol
 [2015-07-25 14:59 UTC] remi@php.net
The following patch has been added/updated:

Patch Name: 0001-Fix-70112-RFE-Allow-dirname-to-go-up-various-times.patch
Revision:   1437836385
URL:        https://bugs.php.net/patch-display.php?bug=70112&patch=0001-Fix-70112-RFE-Allow-dirname-to-go-up-various-times.patch&revision=1437836385
 [2015-07-27 13:24 UTC] remi@php.net
Automatic comment on behalf of fedora@famillecollet.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e811770a68641c85d7e49f84f3230b4ed7a1e808
Log: Fix #70112 RFE Allow dirname to go up various times
 [2015-07-27 13:24 UTC] remi@php.net
-Status: Open +Status: Closed
 [2015-08-04 20:54 UTC] ab@php.net
Automatic comment on behalf of fedora@famillecollet.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e811770a68641c85d7e49f84f3230b4ed7a1e808
Log: Fix #70112 RFE Allow dirname to go up various times
 [2016-07-20 11:37 UTC] davey@php.net
Automatic comment on behalf of fedora@famillecollet.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e811770a68641c85d7e49f84f3230b4ed7a1e808
Log: Fix #70112 RFE Allow dirname to go up various times
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC