Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17409 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38192 invoked by uid 1010); 26 Jul 2005 15:50:32 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 38175 invoked from network); 26 Jul 2005 15:50:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jul 2005 15:50:32 -0000 X-Host-Fingerprint: 63.118.113.4 miami4.us.univision.com Received: from ([63.118.113.4:2178] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6227M)) with SMTP id 30/43-58254-6CB56E24 for ; Tue, 26 Jul 2005 11:50:31 -0400 Message-ID: <30.43.58254.6CB56E24@pb1.pair.com> To: internals@lists.php.net 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> Date: Tue, 26 Jul 2005 11:50:35 -0400 Lines: 103 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1506 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506 X-Posted-By: 63.118.113.4 Subject: Re: [PHP-DEV] [PATCH] Namespace Patch, Alpha 3 From: jrhernandez05@gmail.com ("Jessie Hernandez") 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". Let me know if the above make sense or if you see any problems with this approach. -- Jessie