Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68851 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65046 invoked from network); 2 Sep 2013 13:23:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2013 13:23:30 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.171 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.220.171 mail-vc0-f171.google.com Received: from [209.85.220.171] ([209.85.220.171:42766] helo=mail-vc0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2E/27-29856-15194225 for ; Mon, 02 Sep 2013 09:23:30 -0400 Received: by mail-vc0-f171.google.com with SMTP id ij15so3133518vcb.30 for ; Mon, 02 Sep 2013 06:23:27 -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=e6xkSCgPfFs/Lg+0+ppQENuPXjCykfOjcbhZpLyCTsM=; b=VngaHgI6C5UaQ4Twpg+MQn4Mt1Oqvnfzqm31thlOwMW8yKrfQoGHUsx2AlPHftmTNG EVOdjrWgEDn/5VOQWExhNwslV+010NmkCFTNgdUeGgmItV9ATYsMxH4RY+rzv/PmwF00 CsPF+sn/JpA1GQtLJalIznrUFnGWFhBTgKTyxT6cmHLYsLcscslPQdczQLSCuqYhG500 Ey+Sx9sl8i5gh/o2mJhZjkKyloJTvZGj2WGjJiTeVmSQMBwKEQRMb7/bQjA3OVVLIZVn TrubobZOw8TCdq+nnt+0xou07XEXm1banzESZzDo1GTRfPBqB2cxbhrYJKmAh2Y9eUqy cTfA== MIME-Version: 1.0 X-Received: by 10.220.145.132 with SMTP id d4mr23222334vcv.9.1378128207410; Mon, 02 Sep 2013 06:23:27 -0700 (PDT) Received: by 10.58.94.201 with HTTP; Mon, 2 Sep 2013 06:23:27 -0700 (PDT) In-Reply-To: References: <5220262A.6040702@sugarcrm.com> <5220437A.7050008@sugarcrm.com> <5220D212.3010101@sugarcrm.com> <61FCD6C4A31248078FEAD2BA73D7CD44@gmail.com> <7AF31CC1D1554454AC95AE758D23E92E@gmail.com> Date: Mon, 2 Sep 2013 09:23:27 -0400 Message-ID: To: Nicolas Grekas Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b34347c41fd3d04e5667a38 Subject: Re: [PHP-DEV] Re: Function autoloading From: ircmaxell@gmail.com (Anthony Ferrara) --047d7b34347c41fd3d04e5667a38 Content-Type: text/plain; charset=ISO-8859-1 Nicolas, namespace foo { >> something(); // autoloaded as "something" >> } >> > > That makes sense *for me* for many reasons, but IMHO that's too confusing > for a wider adoption. > Because this doesn't work for function foo\strlen, the only reasonable way > to work with such an autoloader would be to avoid using dynamic namespace > resolution by always using some "use function" or "use namespace". > That's very fragile... > How is it fragile? In fact, I would argue that relying on dynamic namespace resolution (as happens today) is fragile. Because you can't know at compile time (or before hand) what a function will resolve to. That's fine when you want polymorphism, but when you don't (which is most of the time that you're calling a named function) it's not much short of fragile. This encourages explicit, one-execution-path code. I fail to see how that makes things worse than today... In fact, I see it making this better... > I order not to be the one who kills a proposal and be constructive: > > Would some kind of namespace initializers be a good idea? > > That could work this way: > > Any time a non existing function or constant is required, a registered > namespace initializer would be loaded. The big difference being that it > would happen *BEFORE* fallback namespace resolution. The registered > namespace loader would be given only the namespace part of the required > symbol, and that would happen only once per namespace. > > That would have a performance impact, but I would be interested in seeing > real benchmarks. May be we can find a way to make the mechanism light > enough. > > For this performance reason, I would suggest having a registering function > that take the exact namespace for which the loader matches as first > argument: > spl_namespace_register($namespace[, callable $autoload_function) > > $autoload_function would be called only for symbols in $namespace. > > What do you think ? > Is it worth discussing that further? > It's an interesting thought. I think I'd rather see first-class support for modules, but not quite sure there. Actually, thinking about it slightly more, this appears to be trying to hack namespaces into first-class modules. Right now, a namespace is nothing more than compiler aided copy/paste (with the exception of global fallback for functions and constants). It's just a prefix added on to the construct's name. To do this right, you could do it by parsing the name at each dispatch, and then doing a hash table lookup to see if it's been loaded or not yet. But if we're going down that route, why not take the next logical step and make modules first class citizens (with a symbol table, where classes, functions and constants are members of said module, rather than just floating with prefixed names. That way we can attach metadata, access permissions, events, etc around the module, and not just hack in one additional thing. Obviously this is a massive undertaking and quite off topic from here. But if it's worth discussing further, let's open another thread. Anthony --047d7b34347c41fd3d04e5667a38--