Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33960 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49434 invoked by uid 1010); 12 Dec 2007 05:45:16 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 49417 invoked from network); 12 Dec 2007 05:45:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Dec 2007 05:45:15 -0000 X-Host-Fingerprint: 74.163.149.196 adsl-163-149-196.mia.bellsouth.net Received: from [74.163.149.196] ([74.163.149.196:24073] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/BF-38526-B657F574 for ; Wed, 12 Dec 2007 00:45:15 -0500 Message-ID: <97.BF.38526.B657F574@pb1.pair.com> To: internals@lists.php.net Date: Wed, 12 Dec 2007 00:45:09 -0500 User-Agent: Thunderbird 1.5.0.12 (X11/20070530) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 74.163.149.196 Subject: Idea for namespace lookup resolution From: jrhernandez05@gmail.com (Jessie Hernandez) I just thought of something that might be a solution to the lookup rules that we currently have in the namespaces implementation. Whether it's good or not, I just wanted to throw it out there. Here goes: Support a user-defined function named __get_namespace_classes, which will be similar to __autoload. The signature of the function would be the following: array __get_namespace_classes(string $namespaceName); Returns an array of names of classes that are under the specified namespace, or FALSE if the classes under the namespace could not be determined. The above function would be used in the lookup rules as follows (using DateTime as an example): 1) Does the class DateTime exist in the current namespace? 2) If not, and the function __get_namespace_classes exists, call __get_namespace_classes. 3) If the string DateTime is returned in the array from __get_namespace_classes, then autoload that class. 4) If the class is not in the resulting array, or if the result was FALSE, then look for an internal class DateTime. With the above function, you can define classes inside your namespace that are named the same as internal classes without having to explicitly "use" them all over the place. You also solve the problem of namespace imports (sorry, use :-) ): For the above function to work best, the PHP "dir" function, as an example, should be modified to have an additional "use_include_path" argument: object dir(string $directory [, bool $use_include_path]) By passing TRUE as the second argument, the directory will be searched for in the include path. The user can then do something like the following as an implementation of __get_namespace_classes (assuming the user organized it into class per file, as is common): read() ) !== false ) $classes[] = str_replace( '.php', '', $file ); $d->close(); } return $classes; } ?> Let me know what you think! Regards, Jessie