Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87243 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74718 invoked from network); 23 Jul 2015 09:54:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jul 2015 09:54:48 -0000 Authentication-Results: pb1.pair.com header.from=joshdifabio@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=joshdifabio@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.172 as permitted sender) X-PHP-List-Original-Sender: joshdifabio@gmail.com X-Host-Fingerprint: 209.85.212.172 mail-wi0-f172.google.com Received: from [209.85.212.172] ([209.85.212.172:34616] helo=mail-wi0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/90-03755-6E9B0B55 for ; Thu, 23 Jul 2015 05:54:47 -0400 Received: by wibud3 with SMTP id ud3so16264668wib.1 for ; Thu, 23 Jul 2015 02:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=PZIzGKj29/IIhFpYcrkwVPtZqTSAeQXVT8eXR8jHw74=; b=MlJrcXNGnmruhQT+AW3XEz4kDp2AafNMlZCiwEN8EQLruf+LOwcEmWqtj/hwbxWp1c f/CkFU+OjuqkKwAWS9u4T8ES0/HXhrQIEqj2tz4oI9t8Ychokqwtad13hHMQYBTYVTZg QYDO4/852IQF6fKTfKFJ1LfQNLDpAB8ht6NYpg4wyQ42MFSMQ12vW6ukVxiWRuXrn+vm dNFoGayZvDqZ613E0W2Ym7zPX+Qtzqg25g2AOLLCUzsvG7jvM3M+k5yO02Z31BnxM8sn Af2ZtZ6QTFHwIkKI21MRNG5V9DcLKnRqTuVatSV8O8XC2R768QS+nVFSeP+4osomEi1e FPLA== MIME-Version: 1.0 X-Received: by 10.180.87.199 with SMTP id ba7mr15777303wib.81.1437645284200; Thu, 23 Jul 2015 02:54:44 -0700 (PDT) Received: by 10.28.159.73 with HTTP; Thu, 23 Jul 2015 02:54:44 -0700 (PDT) In-Reply-To: References: <55AF84C1.8070403@fedoraproject.org> Date: Thu, 23 Jul 2015 10:54:44 +0100 Message-ID: To: Sara Golemon Cc: Remi Collet , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFE to allow dirname($foo, 2) From: joshdifabio@gmail.com (Josh Di Fabio) Great suggestion, Remi, I'd love to see this change! On Wed, Jul 22, 2015 at 7:49 PM, Sara Golemon wrote: > > On Wed, Jul 22, 2015 at 4:55 AM, Remi Collet 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?