Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17489 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14536 invoked by uid 1010); 2 Aug 2005 09:22:16 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 14521 invoked from network); 2 Aug 2005 09:22:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2005 09:22:16 -0000 X-Host-Fingerprint: 208.187.189.114 unknown Linux 2.4/2.6 Received: from ([208.187.189.114:58070] helo=linus.supernerd.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 0D/A6-04646-74B3FE24 for ; Tue, 02 Aug 2005 05:22:15 -0400 Received: from localhost (localhost [127.0.0.1]) by linus.supernerd.com (Postfix) with ESMTP id 0BFF7E78D2; Tue, 2 Aug 2005 05:42:36 -0700 (MST) Received: from linus.supernerd.com ([127.0.0.1]) by localhost (linus [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13279-10; Tue, 2 Aug 2005 05:42:32 -0700 (MST) Received: from [10.0.0.6] (c-67-161-219-95.hsd1.ut.comcast.net [67.161.219.95]) by linus.supernerd.com (Postfix) with ESMTP id 9EF9FE94CE; Tue, 2 Aug 2005 05:42:30 -0700 (MST) Message-ID: <42EF3C7D.9000105@supernerd.com> Date: Tue, 02 Aug 2005 03:27:25 -0600 User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jessie Hernandez Cc: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at supernerd.com Subject: Re: [PHP-DEV] [PATCH] Namespace Patch, Beta 1 From: john@supernerd.com (John LeSueur) Jessie Hernandez wrote: >Attached is the latest version of the namespace patch! It finally includes >namespace imports and it even includes anonymous namespace support. Also, >the previous bison shift/reduce conflict has been removed. Here is a >summary of its features: > >- Simple imports: import ns:class1; >- Import aliases: import ns:class1 as my_alias; >- Namespace imports: import namespace ns; >- Anonymous namespaces: namespace { class file_class{} } >- Namespace-private classes: namespace ns{ private class prv_class{} } > >Two new functions have also been added to support namespace imports (more on >that below): > >- get_imported_namespaces([$className]) >Returns an array of imported namespaces for the current file. If a class >name is passed, and this class is currently being autoloaded (also meaning >that this function is called inside __autoload), then the list of returned >imported namespaces is based on the file that triggered the __autoload >call. > > > so, if I understand correctly, if your __autoload is defined in a different file(file1) from where the import was called(file2), then get_imported_namespaces() returns the namespace imports for file1. get_imported_namespaces($className) would return for file2, and outside of the __autoload function, get_imported_namespaces($className) would return the namespaces for file1. That seems like complicated semantics. Is there some way this could be simplified? Maybe there should be two functions, one that returns namespaces for file2 and is incorrect(throws an error) to call from anywhere other than __autoload(), and one that returns namespaces for file2. >- autoload_import_class($className, $namespaceName) >Imports a class in a given namespace for the currently executing file (can >ONLY be used inside __autoload!) > >Imports >------- >Imports and namespace imports are handled completely by the user with the >use of the __autloload function. This means that there are no restrictions >on class file naming/directory structure. For simple imports, the class >name will be passed with its full name (including the colons, such as >"ns:class1"). For namespace imports, only the class name will be called. >Since the user needs to determine which namespace (or namespaces) a class >belongs to, the "get_imported_namespaces" function is provided to check the >imported namespaces for the currently-executing file. Once the user is >satisfied with a match, he/she needs to perform an "import" for this class, > > This seems like it would be slow, as the user might have many namespaces(directories) to search for matching files. This would of course be up to the user. And it doesn't bother me that a full namespace import may not be as fast as a more specific import. In development it might be convenient, but at some point, it's not that big a deal to specify the classes you use. >but this needs to be done on the executing file, not the file where >__autoload is defined. For this reason, the autoload_import_class function >is provided. A sample usage of both these functions is at >tests/classes/namespace_autoload.php. > > I like the option of having namespaces, and from the description this seems to be a light method of doing it. It does require some effort from the user. It seems that for most cases __autoload will be the same every time, maybe with different paths or file naming conventions. John