Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54690 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78738 invoked from network); 18 Aug 2011 14:53:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2011 14:53:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmgx.michael@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmgx.michael@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: dmgx.michael@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-ww0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:61138] helo=mail-ww0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/C4-50449-D772D4E4 for ; Thu, 18 Aug 2011 10:53:50 -0400 Received: by wwg11 with SMTP id 11so2001633wwg.11 for ; Thu, 18 Aug 2011 07:53:45 -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 :content-type; bh=8V7GJItZPiaNEHEvevrR/MgHq+c6P0ANh+zvAcKQDPk=; b=WcYO3IlyxoEQhXjxx5RpUrak0bOrVomqz9iEDiv79F4rxI1PwVPy2cLZwCb90ASgB3 jRTEXhXRlcru2DSKxl4LcUZbp9P7jn3PC2KSprbbGKaGlElBLHWaM1EtDuplXO46dTmK ocldwdcXe7XQueWdGP7xsiuMtEzRCuXyDEc6Y= MIME-Version: 1.0 Received: by 10.227.2.136 with SMTP id 8mr1753754wbj.41.1313679225821; Thu, 18 Aug 2011 07:53:45 -0700 (PDT) Received: by 10.217.6.195 with HTTP; Thu, 18 Aug 2011 07:53:45 -0700 (PDT) In-Reply-To: <81.F0.56760.0263C4E4@pb1.pair.com> References: <4E481136.3090508@sugarcrm.com> <4E483284.4010100@googlemail.com> <4E4838E1.3000006@sugarcrm.com> <4E48430D.6070409@googlemail.com> <4E486A50.4010700@sugarcrm.com> <4E48A22E.1040900@googlemail.com> <4E48AD3E.6010801@sugarcrm.com> <4E48C126.50707@sugarcrm.com> <4E48D848.1070407@sugarcrm.com> <81.F0.56760.0263C4E4@pb1.pair.com> Date: Thu, 18 Aug 2011 10:53:45 -0400 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=002215975bfe9a9a9a04aac8c7e5 Subject: Re: [PHP-DEV] [RFC] Function autoloading through spl_autoload* From: dmgx.michael@gmail.com (Michael Morris) --002215975bfe9a9a9a04aac8c7e5 Content-Type: text/plain; charset=ISO-8859-1 I'm not so sure about that. For example, class PDO is PHP core. Suppose I create A\PDO. When PHP is asked for A\PDO and fails to find it then it will die. Correct me if I'm wrong but I think it does NOT go looking for \PDO. Another bugbear is classes will most likely be 1 class = 1 file. Functions will probably end up being all functions of the namespace, 1 file. Perhaps there's another way to do this that isn't as fraught with confusion, though I have no idea of what the engine details are or if it's possible. Suppose you have an autoloading function that triggers the first time a namespace is mentioned to pull up definitions for that namespace. So when the engine sees "namespace A;" declared for the first time It sees if any autoloaders are present for namespace A. If yes, it fires them loading the library files for the namespace. Another, similar, approach is one I've been using in my own framework. When the class autoloader first sees a namespace, it checks the filesystem for a namespace definition file that holds functions and constants of the namespace and then loads it (require_once) along with the requested class. Since my framework is object oriented calls to a function that doesn't belong to a specific class will not be emitted outside of a class method and this has been sufficient to handle the problem for which this RFC is supposed to solve within PHP 5.3. Just a thought. On Wed, Aug 17, 2011 at 5:44 PM, Matthew Weier O'Phinney < weierophinney@php.net> wrote: > > > There's nothing saying you can't have the exact same situation right now > with classes and autoloading, too. > > Example: > > namespace A; > > class ReflectionClass > { /* ... */ } > > class MyClass > { /* ... */ } > > What if you have an autoloader that, on encountering A\MyClass then > loads that file? You've now redefined ReflectionClass for the A > namespace. > > The main difference, of course, is that if ReflectionClass is not > explicitly imported, PHP will barf and tell you it doesn't know about > A\ReflectionClass. > > While I understand your objections, I think that after the functionality > exists, there can be discussions about best practices -- e.g., putting > one function per file when autoloading, or documenting when all > functions for a given namespace will be in a single file. It's really a > matter of the project educating its users -- I don't think it should be > a blocker for implementing it at the language level, though. > > > -- > Matthew Weier O'Phinney > Project Lead | matthew@zend.com > Zend Framework | http://framework.zend.com/ > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --002215975bfe9a9a9a04aac8c7e5--