Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17502 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72621 invoked by uid 1010); 2 Aug 2005 16:51:43 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 72604 invoked from network); 2 Aug 2005 16:51:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2005 16:51:43 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:50498] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 08/67-04646-D94AFE24 for ; Tue, 02 Aug 2005 12:51:42 -0400 Received: (qmail 21368 invoked from network); 2 Aug 2005 16:51:57 -0000 Received: from localhost (HELO ANDI-NOTEBOOK.zend.com) (127.0.0.1) by localhost with SMTP; 2 Aug 2005 16:51:57 -0000 Message-ID: <5.1.0.14.2.20050802072038.03ad8ec0@localhost> X-Sender: andi@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Tue, 02 Aug 2005 09:51:32 -0700 To: Jessie Hernandez ,internals@lists.php.net In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] [PATCH] Namespace Patch, Beta 1 From: andi@zend.com (Andi Gutmans) References: FYI, I haven't had a chance to look at this patch yet (nor a lot of the emails on the subject). After PHP 5.1 goes RC and we start our Unicode work, I should have time to look into it. Interesting to see if it addresses the issues we had in the past. I think some of them weren't solvable although if this only addresses classes it might have. One note, we need to make sure we don't complicate the language too much... But anyway, hopefully next week or so I'll have more constructive feedback. At 12:07 AM 8/2/2005 -0400, 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. > >- 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, >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. > >Namespace-private classes >------------------------- >Classes marked as "private" from within a namespace can only be used by >classes defined in the same namespace. > >Anonymous namespaces >-------------------- >Classes defined inside anonymous namespaces can only be used within the file >that declared the anonymous namespace. > > >I believe the attached patch solves the issues that were presented long ago >for namespaces. Referring to the post by Daniel Cogwill at >http://www.zend.com/lists/engine2/200304/msg00164.html, the following are >my answers to the problems he found at the time: > >1) import-all silently hides local names. >A: If a global class is defined with the same name as a class in a >namespace, and the namespace class has been imported in the same script, >the global class takes precedence. The namespace class can still be used by >using its full name, i.e. namespace_name:class_name. > >2) Interestingly (and I assume this is simply a bug), functions and classes >behave differently wrt to import-all and duplicate definitions. >A: Irrelevant in this patch. > >3) There is no way to hide names from import (i.e. make a name >non-exportable). This is a fundamental namespace feature, and there is >already an appropriate keyword (private). >A: Namespace-private classes are supported, using the "private" keyword. > >4) The semantic meaning of successive imports depends on their relative >ordering. >A: The engine does not attempt to determine which class is included, the >user decides the most appropriate behavior inside __autoload. > >5) The most egregious issue is that an import in an included file affects >the scope of the including file. >A: Imports in this patch only affect the file they are in. > > >Since I could not find a way to add the tests/classes/namespace directory >and subdirectories, I zipped them separately, as before. > >Let me know if you have any questions on the attached patch. > > >Best regards, > >Jessie Hernandez > > > > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php