Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17488 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12819 invoked by uid 1010); 2 Aug 2005 09:16:59 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 12803 invoked from network); 2 Aug 2005 09:16:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2005 09:16:59 -0000 X-Host-Fingerprint: 80.237.132.12 wp005.webpack.hosteurope.de Linux 2.5 (sometimes 2.4) (4) Received: from ([80.237.132.12:57529] helo=wp005.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 08/76-04646-90A3FE24 for ; Tue, 02 Aug 2005 05:16:58 -0400 Message-ID: <08.76.04646.90A3FE24@pb1.pair.com> Received: by wp005.webpack.hosteurope.de running Exim 4.43 using esmtpa from dsl-084-057-008-069.arcor-ip.net ([84.57.8.69] helo=WOMBERT) id 1DzstK-0002Ad-WD; Tue, 02 Aug 2005 11:16:55 +0200 To: "'Jessie Hernandez'" Cc: Date: Tue, 2 Aug 2005 11:16:49 +0200 Organization: bitXtender GbR MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 In-Reply-To: Thread-Index: AcWXF8OBaiigJVrKQR+GkwQ1c5mU/QAKxUIA Subject: RE: [PHP-DEV] [PATCH] Namespace Patch, Beta 1 From: dz@bitxtender.com (=?iso-8859-1?Q?David_Z=FClke?=) References: This sounds awesome. Good job, Jessie. Keep it up! - David > -----Original Message----- > From: Jessie Hernandez [mailto:jrhernandez05@gmail.com] > Sent: Tuesday, August 02, 2005 6:07 AM > To: internals@lists.php.net > Subject: [PHP-DEV] [PATCH] Namespace Patch, Beta 1 > > 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 >