Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94919 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57819 invoked from network); 8 Aug 2016 12:15:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2016 12:15:30 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.172 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.161.172 mail-yw0-f172.google.com Received: from [209.85.161.172] ([209.85.161.172:35198] helo=mail-yw0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/5C-33134-1E778A75 for ; Mon, 08 Aug 2016 08:15:29 -0400 Received: by mail-yw0-f172.google.com with SMTP id j12so303131219ywb.2 for ; Mon, 08 Aug 2016 05:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8JuYfb43mGhtafHoN5jO3ljUGyB33Tvav75DCXaffDw=; b=OcUxMGIoJP+Wdd0/CUo2jYd+Qf7P+rrNpmbyl6bf8NbxX/hPhejANpcEEQwR/2Vrge fnQhZGjn77WpnVtcndmYORR7wsnqMEYq7wq9faEzdJyuXrkl65e+Zi8mPx5BjX1ldJHa 8eSmgTAOPeDhEF0sCFFnGCI2UIotstI8OgKJM7JjW5/XYpRqPQ9z3FRN/LMU09rkdZwm CeZ2R5L63JFRjXn7pG2mEg9LnkvSQvdTfvVq/B4uW5krw4ZxsHx63yqow7MflEezTuEn GVaYvn+95qKWzw3MZuJ5z9JXqBt+G2aBPTldU5K3ZLGc0I5QregWYRHMWt92hQb9X9Ot D22w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8JuYfb43mGhtafHoN5jO3ljUGyB33Tvav75DCXaffDw=; b=aWtnCGHmgfSLhDKNaqBf3AuOaJccROEASS0FCb+GPlbq6caLKRQ/9+SYMkIG0YM9SJ RBl9hpDSx4Dky8cKMfIIkIi/PDhFm7z6bqk9OCzCkxnV2Hbbb7jnYjWRCJItIIutIb1c qPY8elANQKJLjqSVKdAEf9UIX8ZJqJhET2mu/SUPUE4dC4uTxHaaD/w0AHqA4rprvSF4 mYuhjphUuiVdZy8VYUYYrkrcDfY7raoWcactZujygfNlWE5tz8LIqOVjxRrxmrSeeqtU g9uNQxywa+Oi66eCcKt6y2lkXxAzjur2MycFus+xkiaYO003jIePW/nEAVUdzT/0Km+M b6KQ== X-Gm-Message-State: AEkooutjLn4NAyCHGNREoppumKExEcumyLXPGE8QTIqE7th8lKVqzTpPUrms9vOe6+NPKWsNZlpOdXcW/wjRTA== X-Received: by 10.129.102.86 with SMTP id a83mr66872106ywc.76.1470658526417; Mon, 08 Aug 2016 05:15:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.129.131.129 with HTTP; Mon, 8 Aug 2016 05:15:25 -0700 (PDT) In-Reply-To: <6600076c-d046-bdca-f339-79894781a996@gmail.com> References: <6600076c-d046-bdca-f339-79894781a996@gmail.com> Date: Mon, 8 Aug 2016 14:15:25 +0200 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a114909d60d988405398e5f66 Subject: Re: [PHP-DEV] Function auto-loading From: nikita.ppv@gmail.com (Nikita Popov) --001a114909d60d988405398e5f66 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Aug 8, 2016 at 12:51 PM, Rowan Collins wrote: > On 07/08/2016 23:42, Davey Shafik wrote: > >> Perhaps the solution is to look at this as a forward-only feature, rathe= r >> than a backfill. >> >> We only support autoloading for unambiguous names =E2=80=94 if you want = the >> autoloader to be called, either >> import the function with use, or use a [fully] qualified name. >> >> This should remove the ambiguities and performance concerns. >> > > I actually quite like this suggestion, because it fits with the use case = I > see as being most common: replacing static-only classes with a namespace = of > related functions. (Remember that "static classes" were rejected at RFC i= n > favour of exactly this.) > > > To be clear, the case we'd be "refusing" to autoload (other than global > functions themselves) would be a function in the *exact* current namespac= e: > > namespace Acme\Foo\Bar; > do_something(); // won't autoload > > But that only matters if namespace "\Acme\Foo\Bar" is split over multiple > files. In this case, the declaration of "Acme\Foo\Bar\do_something()" wou= ld > probably be in the same file anyway, so not need autoloading. > > > Given that we have hierarchical namespaces, this seems a more likely > scenario: > > namespace Acme\Foo\Bar; > // function autoload for 'Acme\Foo\Bar\Utilities\do_something' > Utilities\do_something(); > > Or importing as an alias: > > namespace Acme\Foo\Bar; > use Acme\Stuff\Utilities as Util; > // function autoload for 'Acme\Stuff\Utilities\do_something' > Util\do_something(); > > > Note that an unqualified function call "do_something()" already doesn't > look in any imported namespaces, so "use Acme\Stuff\Utilities;" doesn't d= o > anything to function name resolution. > > So we would be defining a simple rule: "the function autoloader will be > called at run time for any namespace-qualified function name which is not > already defined". > > > This feels like a better compromise than an autoload cache, because I can > see the invalidation rules getting messy, and heavily-used global functio= ns > still firing the autoloader for many different possible prefixes. > I like this idea as well. In a previous thread I suggested to delay the autoloader call for unqualified function calls until after the check for an existing global function. But just not calling the autoloader at all for unqualified calls is the better solution, as it removes one pretty arbitrary factor (does this global function exist?) from the autoloader behavior. Nikita --001a114909d60d988405398e5f66--