Great suggestion, Remi, I'd love to see this change!

On Wed, Jul 22, 2015 at 7:49 PM, Sara Golemon <poll...@php.net> wrote:
>
> On Wed, Jul 22, 2015 at 4:55 AM, Remi Collet <r...@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;
> }
>
> -Sara

Let's assume that we implement this function in userland, either in a Composer
package or more likely in a functions.php file in our project, which Composer or
our project's bootstrap includes for us.

Now, most often, dirname(... dirname(__DIR__) ...) is used in application entry
points during the bootstrapping process. In my experience, it's most commonly
used in order to include an autoloader or some bootstrap file which itself is
responsible for including the autoloader.

In other words, dirname(...) is generally used before we have access to our
includes and classes (no autoloader). Which means, if we were to simply
implement this in userland, we'd have to either write require
dirname(...) in order
to load the dirname_n function every time we need to use it, which would
obviously defeat the object, or conditionally declare the function everywhere
it's needed, which wouldn't be ideal.

Is there some more elegant way this could work in userland which I've missed?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to