Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68848 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59189 invoked from network); 2 Sep 2013 12:48:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2013 12:48:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=nicolas.grekas@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nicolas.grekas@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.41 as permitted sender) X-PHP-List-Original-Sender: nicolas.grekas@gmail.com X-Host-Fingerprint: 209.85.212.41 mail-vb0-f41.google.com Received: from [209.85.212.41] ([209.85.212.41:46558] helo=mail-vb0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/06-29856-B1984225 for ; Mon, 02 Sep 2013 08:48:27 -0400 Received: by mail-vb0-f41.google.com with SMTP id g17so3086110vbg.0 for ; Mon, 02 Sep 2013 05:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=1l4cxpyuUrHjuPzVhXMpPVtsvmc2xHhP/qmW3QHj368=; b=u+sIfM1pf4GZbSHX3SdzBHPxAIBHkoeuIaOIMixaNKqL1PDxEHlVxEJVd32eyPMANH c9b6cGlnDlkrS1M8dKApYv/GZrHLe9WBF2+wQLtjPQKbHsrfhzwgoqcwFYbFAD7wOFVg zHcCMttYb3P41sx8OhiSnN2fEts9MiyfDZdh+dLfO5Xlp7lfrUaTjNyW94qnGNYjZZaj bnWia1o7JR7fqnuEvLNWUfsHwvoAerBR+f+skmeCrcVZDGbvX7Wra2b+UorIz9eye6hu vxyqy34Qw6V/IUgs/BCOee6l35IjumkS1W7fRqfQMHhePxQCQmiCIfU7dsJecadK+OMn 16Bg== X-Received: by 10.58.155.68 with SMTP id vu4mr2910379veb.21.1378126104332; Mon, 02 Sep 2013 05:48:24 -0700 (PDT) MIME-Version: 1.0 Sender: nicolas.grekas@gmail.com Received: by 10.52.249.80 with HTTP; Mon, 2 Sep 2013 05:48:04 -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 14:48:04 +0200 X-Google-Sender-Auth: R4Ay81ViJMCeKIAPAy7id3HhkXU Message-ID: To: Anthony Ferrara Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b604d02e7908704e565fcec Subject: Re: [PHP-DEV] Re: Function autoloading From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --047d7b604d02e7908704e565fcec Content-Type: text/plain; charset=ISO-8859-1 > > 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... 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? Nicolas --047d7b604d02e7908704e565fcec--