Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56067 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 772 invoked from network); 4 Nov 2011 11:19:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2011 11:19:48 -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.216.177 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.177 mail-qy0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:43677] helo=mail-qy0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/91-23221-25AC3BE4 for ; Fri, 04 Nov 2011 06:19:47 -0500 Received: by qyk10 with SMTP id 10so2364610qyk.8 for ; Fri, 04 Nov 2011 04:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=6HGGagfZoK2br0N/DixdRevVZvMlBWCMEDrWjSNKEt4=; b=BQEnDFvisGZGXAgN3q+Zcw1roYnTDn01JEuvxxWwXf1xGRbguRhEtWc+hveIvmeQQB 3rs/HZ+1f8IN1BBm4PCDZCZH1xFaoYPRySUT0rNbWMZqa7qLNDKGsSVZsZvRTAjfyhMw Slgg+Txa/cMIGtE8PkF/8Z/ydurw61yF5/STY= MIME-Version: 1.0 Received: by 10.229.36.202 with SMTP id u10mr1675505qcd.203.1320405583403; Fri, 04 Nov 2011 04:19:43 -0700 (PDT) Received: by 10.229.6.202 with HTTP; Fri, 4 Nov 2011 04:19:43 -0700 (PDT) In-Reply-To: <002f01cc9ade$92c62c60$b8528520$@com> References: <4E208FE7.4020606@sugarcrm.com> <00d401cc9a59$ccf273b0$66d75b10$@com> <68B9654F-EFF9-41FE-866D-B2F838C3AFCE@gmail.com> <002f01cc9ade$92c62c60$b8528520$@com> Date: Fri, 4 Nov 2011 07:19:43 -0400 Message-ID: To: Jonathan Bond-Caron Cc: Will Fitch , PHP Internals List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] SplClassLoader From: ircmaxell@gmail.com (Anthony Ferrara) Jonathan, > The problem with spl_autoload_register() is it isn't clear what the > autoloading function is supposed to do if the class if not found. Then that's a documentation problem. If you throw an exception in yours, sure that's going to cause problems for anyone else. It's 100% possible (and easy) to play nice. But that brings up another problem with PSR-0. It's possible to use 100% valid PHP and have it throw a fatal error. Let's assume a file exists named foo/bar.php new foo\bar; new foo_bar; That will fatal error 100% of the time (as long as both of those classes aren't in that file), since they both map to the same file, *and* PSR-0 mandates require instead of require_once. So even if I declare an autoloader later to load my foo_bar class, it won't work because it'll never get there. Additionally, since it's not checking the existance of the file, it's impossible for me to add a class to an existing namespace from outside of its root. Say we have /lib/foo/bar/baz.php. If I wanted to add a class \foo\bar\bat.php, I'd **have** to add it to that directory, other wise I'd get a fatal error. It's not a far cry. That's basically what Kohana does right now with their autoloader... So that's two more inconsistencies with what's 100% valid PHP but could cause fatal errors with PSR-0. @Ferenec >I think that the best solution would be having a generic autoloader infras= tructure in the core, and having separate autoloading strategies(http://en.= wikipedia.org/wiki/Strategy_pattern) offered, and one of them could be PSR-= 0(we could also add the PEAR/PEAR2 autoloader, etc.). That's something that I could get behind.. @Andre >It will be a more modern alternative to http://www.php.net/manual/en/funct= ion.spl-autoload.php And I don't feel that function belongs in the core at all either. It's there, so whatever, but at least that's consistent with how PHP behaves... > So yes, there is already something like this in core, so I really don't g= et why you are so against this, not seeing the wood for the trees? :) Well, nothing like this exists in core. First, PSR-0 doesn't degrade gracefully. If it can't map, it fatal errors. Nothing else does so in the core in an area where it's 100% possible to recover anyway. Secondly, nothing in the core requires you to adhere to a code-level convention for it to work. I'm sure there are more arguments against that, but eih. Not seeing the forest for the trees? On the opposite. I see what this will open up if included. Why can't my autoloader be put in the core when PSR-0 is in it? Based on what you said, it's 100% optional, so why not? Should Runkit be put in core? Sure, it's optional to use, so why not? Heck, while we're at it, all of PECL should be moved in core. Who cares how stable or nice they interact with the core. After all, the core of the language is not like it's widely used by others. The language should care about *possibility* not picking a side when it's trivial to implement in PHP land. You're talking about saving 8 or 10 lines of PHP code... So I would argue that it's more not seeing the forest because you're looking too close at one tree... Anthony On Fri, Nov 4, 2011 at 6:43 AM, Jonathan Bond-Caron wro= te: > On Thu Nov 3 03:06 PM, Will Fitch wrote: >> Wouldn't you consider spl_autoload_register an interoperability >> solution? =A0Only your defined autoloading function would then need to >> know how your file system is structured, there'd be no need for >> include_path declarations and you wouldn't have to explicitly declare >> paths for each class. >> > > The problem with spl_autoload_register() is it isn't clear what the > autoloading function is supposed to do if the class if not found. > So no I don't think spl_autoload_register() solves an interoperability > problem. SplClassLoader somewhat does a better job by forcing a common > implementation... > > function FrameworkA_autoload($class) { > =A0if( !isset($AmapToFile[$class]) ) > =A0 =A0 throw new Exception('Class '. $class . ' not found!'); > > =A0include_once($AmapToFile[$class]); > } > function FrameworkB_autoload($class) { > =A0require_once($BmapToFile[$class]); > } > function FrameworkC_autoload($class) { > =A0include_once($CmapToFile[$class]); > } > > spl_autoload_register('FrameworkA_autoload'); > spl_autoload_register('FrameworkB_autoload'); > spl_autoload_register('FrameworkC_autoload'); > > So both 'FrameworkB_autoload', 'FrameworkC_autoload' are never called. > > Btw, I would hope that any 'standard' would actually that try to talk abo= ut > other autoloaders and how they should behave. > > https://gist.github.com/221634 > > See comments about include() or require() > > >