Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17411 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61841 invoked by uid 1010); 26 Jul 2005 19:08:15 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 61810 invoked from network); 26 Jul 2005 19:08:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jul 2005 19:08:15 -0000 X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from ([81.169.182.136:36885] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.0 beta r(6227M)) with SMTP id 1E/F0-58254-F3386E24 for ; Tue, 26 Jul 2005 14:38:55 -0400 Received: from [192.168.1.3] (dsl-082-083-252-245.arcor-ip.net [82.83.252.245]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id C234D35C36E; Tue, 26 Jul 2005 20:56:31 +0200 (CEST) Date: Tue, 26 Jul 2005 20:38:58 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1531018265.20050726203858@marcus-boerger.de> To: Jessie Hernandez Cc: internals@lists.php.net In-Reply-To: <30.43.58254.6CB56E24@pb1.pair.com> References: <52.31.61486.E8DCDD24@pb1.pair.com> <1122328113.647.16.camel@boost.home.ahk> <538910800.20050725235918@marcus-boerger.de> <79.5B.58254.6DCA5E24@pb1.pair.com> <1374121835.20050726101045@marcus-boerger.de> <30.43.58254.6CB56E24@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [PATCH] Namespace Patch, Alpha 3 From: helly@php.net (Marcus Boerger) Hello Jessie, Tuesday, July 26, 2005, 5:50:35 PM, you wrote: > Hi Marcus, > "Marcus Boerger" wrote in message > news:1374121835.20050726101045@marcus-boerger.de... >> >> > 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. >> >> None of the above makes any sense. Look __autoload() is just bein called > at >> any place where a class is missing. So looking for the file first and then >> loading __autoload(I) makes no sense whatsoever. IMO what we need here is > a >> default implementation for import behavior accomplished by __autoload(). > So >> for example "import ns:cls;" leads to "__autoload('ns:cls')". Here the SPL >> default implementation would relpace all ':' with the directory divider > '/' >> or '\', append '.inc' or '.php' or '.inc.php' and append the result to all >> directories in the include_path to look for the file. If were are to > support >> import with '*' the the autoload implementation would need to take care of >> this and load all matching files. A user land implementation can easily >> achieve that by using SPLs (Recursive)DirectoryIterator and > FilterIterator. >> > Regarding a fully-specified class import, such as ns:cls, if I simply remove > my include logic, then __autoload('ns:cls') would automatically be called. > There are no issues with this type of import. > Now, namespace imports (wildcard imports) are a different story. Maybe I did > not make my explanations clear enough, but you basically agreed to point #3 > in my previous email. Now, the class name cannot simply be passed to > __autoload, because there is no way for __autoload to know to which > namespace the class belongs to, and you only want __autoload to include the > classes belonging to the namespaces that have been imported. That is why the > list of imported namespaces for the __calling__ file must be accessible > somehow to the __autoload function, either as an additional argument or by > having the first argument be an array/object. > So the namespace imports will work like how you described simple imports, > but with a slight twist. To quote you: > "Simple" Imports > ---------------- >> So for example "import ns:cls;" leads to "__autoload('ns:cls')". Here the > SPL >> default implementation would relpace all ':' with the directory divider > '/' >> or '\', append '.inc' or '.php' or '.inc.php' and append the result to all >> directories in the include_path to look for the file. > By slightly modifying your sentence, we implement namespace imports: > Namespace Imports > ----------------- > Here the SPL default implementation would, in a loop, prefix the class name > with each imported namespace, replace all ':' with the directory divider '/' > or '\', append '.inc' or '.php' or '.inc.php' and append the result to all > directories in the include_path to look for the file. > For example, here is how the userland __autoload might look (notice that > this code is exactly what I provided in the last post). In this example, the > user has the directory structure as "namespace-name/class-name.php". > function __autoload($className, $importNamespaces) > { > $paths = explode( PATH_SEPARATOR, get_include_path() ); > foreach( $paths as $path ) > { > foreach( $importNamespaces as $ns ) > { > $fullPath = $path . DIRECTORY_SEPARATOR . str_replace( ':', > DIRECTORY_SEPARATOR, $ns ) . DIRECTORY_SEPARATOR . $className . '.php'; > if( file_exists( $fullPath ) ) > { > require_once( $fullPath ); > break; > } > } > } > } ?>> > Let me know if the above make sense or if you see any problems with this > approach. On a first sight i only see that 'break' should be 'return'. Best regards, Marcus