Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19771 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94424 invoked by uid 1010); 28 Oct 2005 01:03:47 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 94409 invoked from network); 28 Oct 2005 01:03:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2005 01:03:47 -0000 X-Host-Fingerprint: 68.215.110.203 adsl-215-110-203.mia.bellsouth.net Received: from ([68.215.110.203:6292] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 94/60-22886-2F871634 for ; Thu, 27 Oct 2005 21:03:46 -0400 Message-ID: <94.60.22886.2F871634@pb1.pair.com> To: internals@lists.php.net Date: Thu, 27 Oct 2005 21:03:43 -0400 References: <435FCBC1.3030105@unFocus.com> <43615AC9.9000509@unFocus.com> Lines: 57 User-Agent: KNode/0.9.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Posted-By: 68.215.110.203 Subject: Re: [PHP-DEV] Re: Namespace methods From: jrhernandez05@gmail.com (Jessie Hernandez) Hi Kevin, Kevin Newman wrote: > Thank you for the info. > > I have some questions/suggestions (they may be silly - please feel > welcome to tell me so, if they are): > > You have solved the problem (grievance number 5) of file based scoping, > by introducing a function that can only be used within __autoload (the > autoload_import_class function). Is that function meant to be called > from within the class file? If so, I'd like to offer an alternative, > that would allow usage even outside of the __autoload function. > The autoload_import_class function has nothing to do with solving the file-based scoping problem. The way this was done internally was to have a HashTable with the file names as key, and the values are each a HashTable containing the import information. The autoload_import_class function was created in order for full namespace imports to be resolved from the __autoload function, regardless of which file the __autoload function is in. For example, if we had two files, test.php and autoload.php, and from test.php you have a statement "import namespace my_ns" and you reference a class "my_class", then as soon as you try to reference my_class, the __autoload function will be called (which is in autoload.php). There needs to be a mechanism in which a namespace import can be resolved from another file. The autoload_import_class does just that. You pass it the class name and namespace name, and inside this function, it adds this information to the import HashTable of the file that triggered the __autoload call (in this case, test.php). After exiting __autoload, the class is resolved and can be used by test.php. > Namespaces are generally implemented in file based languages (like c, > c++, c# etc.), so there isn't an issue with clearing out imported > namespaces when a file ends - but since (let me know if this is an > incorrect assumption) PHP is an inline based interpreter - it would make > sense to have a way to remove namespaces after they have been imported. > So the first suggestion is to add an unimport (export?) function that > would do just that - remove imported classes (or functions/vars, etc.) > from the current (or global?) scope. > This is unnecessary, as there is a separate import HashTable for each file, like I explained above. I believe that what you were trying to accomplish with your pseudocode was what is already being done internally, so I don't think it's relevant after having explained the above (correct me if I'm wrong). Regards, Jessie