Re: RFE to allow dirname($foo, 2)
| From: | Remi Collet | Date: | Thu, 23 Jul 2015 05:28:56 +0000 |
| Subject: | Re: RFE to allow dirname($foo, 2) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87242@lists.php.net to get a copy of this message | ||
Le 22/07/2015 20:57, Marco Pivetta a écrit :
> On 22 July 2015 at 19:49, Sara Golemon <pollita@php.net
> <mailto:pollita@php.net>> wrote:
>
> On Wed, Jul 22, 2015 at 4:55 AM, Remi Collet
> <remi@fedoraproject.org
> <mailto:remi@fedoraproject.org>> wrote:
>> See https://bugs.php.net/bug.php?id=70112
>>
> I'm not inherently against it, but this really really sounds like
> a job for a userspace function.
>
> function dirname_n($path, $n) { while (($path !== '.') && $n--)
> $path = dirname($path); return $path;
> }<http://www.php.net/unsub.php>
>
>
> Indeed. What need is there to add a functionality to a relatively
> simple function like this one? What's the actual advantage that
> cannot be achieved in userland code?
>
Legibility and the frequency of the usage of dirname(dirname(...
in various pieces of code.
See
https://github.com/search?q=dirname+__DIR__+language%3Aphp&ref=searchresults&type=Code&utf8=%E2%9C%93
As github search doesn't allow to search for (, I use __dir__ which
probably hides more usage.
As "n" is usually 2 or 3, nobody will write a userland function.
Remi
> Greets,
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>