Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68718 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19019 invoked from network); 30 Aug 2013 11:28:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 11:28:12 -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.212.50 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.50 mail-vb0-f50.google.com Received: from [209.85.212.50] ([209.85.212.50:33373] helo=mail-vb0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B8/2A-64695-AC180225 for ; Fri, 30 Aug 2013 07:28:10 -0400 Received: by mail-vb0-f50.google.com with SMTP id x14so1182406vbb.23 for ; Fri, 30 Aug 2013 04:28:07 -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=lQI0KIRIhQ+dZ32d/spfjV75Pf0YLjeIx7bWMTQOlCk=; b=oU9NMayxWSpSYpA1G4xsQtDC8YSFF6qpZ3xbSc3ZfDfIPABtwtgELoopZDQ928koTu DFUK7ejeWiimIgIziA5R8L8mE3NFr7ip5qrSPRI5rvCr+7VUY5Gv52p3QkgBqdS0hdRD a0zk+2OteYFzZMx8GAt7J0FwxMrWmNx5fFfhwRn5pMFc16q0CXE8y01f+7or4UO0ed5k ICv7Hgm444TQ9MIe6eMMH1IYwJb/50fi43eUtydbZ//ABT8cEQ7SzbR7KdAPVugGcp5i ORoFjUOJdGBt8Pc4/rqfT7fKuASmpMs6WmT91GrE4WwSCnHshCoiSw8+RUq7ufqVDVwx b0sg== MIME-Version: 1.0 X-Received: by 10.58.137.167 with SMTP id qj7mr7843454veb.1.1377862087795; Fri, 30 Aug 2013 04:28:07 -0700 (PDT) Received: by 10.58.94.201 with HTTP; Fri, 30 Aug 2013 04:28:07 -0700 (PDT) In-Reply-To: <5220262A.6040702@sugarcrm.com> References: <5220262A.6040702@sugarcrm.com> Date: Fri, 30 Aug 2013 07:28:07 -0400 Message-ID: To: Stas Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b677efa4aed5904e5288430 Subject: Re: [PHP-DEV] [DRAFT] [RFC] Function autoloading From: ircmaxell@gmail.com (Anthony Ferrara) --047d7b677efa4aed5904e5288430 Content-Type: text/plain; charset=ISO-8859-1 Stas, On Fri, Aug 30, 2013 at 12:57 AM, Stas Malyshev wrote: > Hi! > > > I have created a new draft RFC implementing function and constant > > autoloading in master: > > > > https://wiki.php.net/rfc/function_autoloading > > > > All feedback is welcome. > > 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). I don't think that's a fair argument. It's a bit "We don't support function autoloading, so function autoloading doesn't make sense". As far as complicated and fragile logic, as Nikita pointed out, you could put all of your functions inside of a "functions,php" in a particular namespace. Then, with use function, you can capture the missing function call, and cut off the function name, require_once /path/to/namespace/functions.php, and be good. Or, alternatively, you can keep a mapping of function->filename. There's no need or requirement for one-class, one-function or one-constant. Furthermore, I think that's up to the community to decide how to do. They mostly settled on a 1-class-to-1-file rule (which was not the case prior to __autoload/spl_autoload). I am fully confident that they will find a way that makes sense, if given the ability. > Putting autoloading of different entities into one function makes very > little sense to me - why would the same code load both classes and > functions? How would it do that besides ugly switch that just stuffs two > completely different logic pieces into one function for no reason? The > example given in the RFC is certainly not what anybody would actually > want their autoloaders to do, so I fail to see any case for doing it and > for putting loading more than one entity into one function (that given > that autoloading function would be desirable at all, which it still > doesn't seem so for me). > That's why this is a RFC which is up for discussion. That's why this is a draft instead of a proposal. Would you rather see: bool php\autoload_class_register($callback, $prepend)) bool php\autoload_function_register($callback, $prepend) bool php\autoload_constant_register($callback, $prepend) Would you rather having the single autoload regstier, but enforcing that type must be a single type? Would you rather see interfaces? interface php\Autoloader {} interface php\AutoloaderClass extends php\Autoloader { public function loadClass($name); } interface php\AutoloaderFunction extends php\Autoloader { public function loadFunction($name); } interface php\AutoloaderConstant extends php\Autoloader { public function loadConstant($name); } bool php\autoload_register(php\Autoloader $loader, $prepend); The syntax provided in this RFC is a proposal. It's not set in stone. If you don't like it, let's work towards a better one! Thanks, Anthony --047d7b677efa4aed5904e5288430--