Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17400 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84907 invoked by uid 1010); 26 Jul 2005 03:24:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 84892 invoked from network); 26 Jul 2005 03:24:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jul 2005 03:24:06 -0000 X-Host-Fingerprint: 65.9.70.25 adsl-9-70-25.mia.bellsouth.net Received: from ([65.9.70.25:26755] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6227M)) with SMTP id 79/5B-58254-6DCA5E24 for ; Mon, 25 Jul 2005 23:24:06 -0400 Message-ID: <79.5B.58254.6DCA5E24@pb1.pair.com> To: internals@lists.php.net Date: Mon, 25 Jul 2005 23:24:02 -0400 References: <52.31.61486.E8DCDD24@pb1.pair.com> <1122328113.647.16.camel@boost.home.ahk> <538910800.20050725235918@marcus-boerger.de> Lines: 123 User-Agent: KNode/0.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Posted-By: 65.9.70.25 Subject: Re: [PHP-DEV] [PATCH] Namespace Patch, Alpha 3 From: jrhernandez05@gmail.com (Jessie Hernandez) Marcus Boerger wrote: > > You already have the ability to overload __autoload or provide several > userspace __autoload functions that would be called one after another > until the first succeeds. What else do you want? Besides the fact that > i am still convinced that we should find a way to pass the full namespaced > name to __autoload instead of just the classname. If you ask me not doing > so is simply an error. > I still think that the namespace importing logic/file-naming convention is the cleanest, but if __autoload is to be used, then I currently see three approaches to this: 1) Search in each directory in the class_path (or include_path) for "namespace-name/class-name.php". When the first file is found, then the full class name will be generated from that and passed on to __autoload, e.g. if you import the my_ns namespace and use class1, then my_ns/class1.php will be searched in the path and then __autoload will be called with "my_ns:class1". Requirements ------------ - Namespace/class naming convention Pros ---- - Full class name is passed to __autoload Cons ---- - Performance loss (when the directories are searched, the path to the class file is already known before __autoload is called, so generating the full class name from the path, calling __autoload, only to then str_replace colons with slashes and including that seems unnecessary). - When a class name exists in more than one imported namespace, the first one found will be passed to __autoload (no way to disambiguate). 2) Like (1), but search all the directories and pass an extra argument (or pass an array or object as the first argument) to __autoload indicating the directories where the class name was found. The first argument would be the class name, the second argument (or an additional key in the array) would contain the paths (or namespace names, whichever). The user would be responsible for disambiguation in case a class exists in multiple imported namespaces. Requirements ------------ - Namespace/class naming convention Pros ---- - No ambiguity - The include behavior is handled completely by the user Cons ---- - In the majority of cases, a class name will not appear in more than one namespace, so there will be a performance loss by having to search all the directories in the class/include_path, even though there was a match on the first directory. 3) Simply pass an extra argument (or pass an array or object as the first argument) to __autoload containing the names of the imported namespaces of the calling file. __autoload can then use this array against the class name and perform its own lookup. Requirements ------------ - None Pros ---- - A namespace/class naming convention is not forced - The include behavior/lookup is handled completely by the user - No performance loss (all that's passed to __autoload is the class name and an array of imported namespaces, and this is done immediately). Cons ---- - IMHO, I think most users would maintain a naming convention similar to Java's, so the user would have to add code for something which the language should handle for them. This can be minimized, though, if a function is added to handle this common behavior. The function can be called by the user in __autoload and will look something like the following (of course, the code would be in C): I still think the namespace import behavior should be separate from the __autoload function. Of course, this is just me. What does everyone else think? I'd like to gather opinions on which is preferred. I will also like to know if a separate class_path is preferred (as I have in my last patch) or if just leaving include_path is what most prefer. -- Jessie