Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68711 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5340 invoked from network); 30 Aug 2013 09:42:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 09:42:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.47 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.219.47 mail-oa0-f47.google.com Received: from [209.85.219.47] ([209.85.219.47:52083] helo=mail-oa0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6E/37-64695-31960225 for ; Fri, 30 Aug 2013 05:42:43 -0400 Received: by mail-oa0-f47.google.com with SMTP id g12so1987681oah.6 for ; Fri, 30 Aug 2013 02:42:40 -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=45dsWWVKcIB/IzLwzw3KL2dSuSY/3qEBME6XbpcUw9A=; b=i+/L2gK6VMqAKQQfU6/RO1Qbq1I9KAuBupmpAkHsMAVsEL9FAp73o6mQBz0pqFFkOX IWZw/T75YPvgksJEuTHIzr313kb2Kp414hfVx6viwJuWOTfg7H0ACl53p1DAUfv0crXQ d5O8brK9IP2F7q6hWbnovii32Kt5fS6Pg9h7DNwBcPYcGiYKUIl8ZMGdYB37Svcp3t1N Uu+KXUVUzAM6OHRTTquhp9JLfkKx9h7d+K3thQudpIGKnXTSXYWW3E0a1jKenwaKNU3/ cr8Xqbp7opvpqOBWP+ADyfpDunC7ofIcNQtLrT+SM1aJ0joA5lBfYvH5Q87gzqFxSGvy iFqw== MIME-Version: 1.0 X-Received: by 10.182.98.162 with SMTP id ej2mr6080248obb.61.1377855760567; Fri, 30 Aug 2013 02:42:40 -0700 (PDT) Received: by 10.182.98.8 with HTTP; Fri, 30 Aug 2013 02:42:40 -0700 (PDT) In-Reply-To: <5220262A.6040702@sugarcrm.com> References: <5220262A.6040702@sugarcrm.com> Date: Fri, 30 Aug 2013 11:42:40 +0200 Message-ID: To: Stas Malyshev Cc: Anthony Ferrara , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b2e46f02914e904e5270bb3 Subject: Re: [PHP-DEV] [DRAFT] [RFC] Function autoloading From: nikita.ppv@gmail.com (Nikita Popov) --047d7b2e46f02914e904e5270bb3 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Aug 30, 2013 at 6:57 AM, Stas Malyshev wrote: > I think it is an unnecessary complication. Classes fit autoloader > paradigm nicely, since the usual pattern is one class per one file > (actually recommended in PSR), so it is easy to establish one-to-one > automatic mapping between classes and files (also recommended in the > PSR). But for functions nobody does this. This means that to implement > function autoloader one will need to have a complicated and fragile > logic (since there's no way to ensure this logic would be in sync with > actual content of files containing multiple functions). > For functions people do not commonly use a one-to-one mapping between a function name and a file, that's true. But there commonly *is* a one-to-one mapping between a *namespace* and a file. So if you have a function foo\bar\baz it will be in the file foo/bar.php (which defines all functions of namespace foo\bar). I think this is a rather common pattern in functional (or function-heavy) libraries and I use this myself too. Apart from such a namespace-to-file mapping you can also use the same approach some people use for classes: Just pregenerate the name-to-file mappings in an array, then loop up from there (e.g. theseer/autoload). This is one of the rare autoloading concepts that actually properly works in PHP (much unlike PSR-0, which fails to honor case-insensitivity). > Moreover, since this replaces a simple hash lookup with additional two > function calls (and also other operations included in those) everywhere > in the engine, it will also have performance impact of one of the most > frequently used operations in the engine - function calls - while > providing absolutely no benefit for 100% of existing code and 99.99% of > future code. > I'd assume that this isn't yet the final patch and it will be improved to make sure that there is no significant performance regression for function calls not making use of autoloading. This should just be a matter of inlining the part of the function with the direct hash lookup and avoiding a duplicate lcname call. (Maybe in the engine just keep the old if (zend_hash_find(...)) and add an else { autoload(); }.) Putting autoloading of different entities into one function makes very > little sense to me - why would the same code load both classes and > functions? I don't think it makes much sense to use the same function to autoload classes and functions, but I think it makes sense to autoload both functions and constants with the same mechanism, because presumably both would follow the same naming-convention (e.g. the namespace-to-file mapping mentioned above). So I think this is a useful feature and I definitely don't see a reason why we need to explicitly prevent it. Anyway, I'm +1 on this :) PHP has been neglecting it's functional sides. The "use function" RFC and this one work on improving this a bit. Nikita --047d7b2e46f02914e904e5270bb3--