Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19769 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56714 invoked by uid 1010); 27 Oct 2005 22:55:11 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56699 invoked from network); 27 Oct 2005 22:55:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2005 22:55:11 -0000 X-Host-Fingerprint: 67.18.30.226 unknown Windows 2000 SP4, XP SP1 Received: from ([67.18.30.226:1842] helo=NEOCURVE01.neocurve.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 80/6C-22886-DCA51634 for ; Thu, 27 Oct 2005 18:55:09 -0400 Received: from [127.0.0.1] ([24.97.207.99]) by neocurve.com with MailEnable ESMTP; Thu, 27 Oct 2005 17:55:00 -0500 Message-ID: <43615AC9.9000509@unFocus.com> Date: Thu, 27 Oct 2005 18:55:05 -0400 User-Agent: Thunderbird 1.4.1 (Windows/20051006) MIME-Version: 1.0 To: Jessie Hernandez CC: internals@lists.php.net References: <435FCBC1.3030105@unFocus.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 0543-2, 10/27/2005), Outbound message X-Antivirus-Status: Clean Subject: Re: [PHP-DEV] Re: Namespace methods From: CaptainN@unFocus.com (Kevin Newman) Thank you for the info. I have some questions/suggestions (they may be silly - please feel welcome to tell me so, if they are): You have solved the problem (grievance number 5) of file based scoping, by introducing a function that can only be used within __autoload (the autoload_import_class function). Is that function meant to be called from within the class file? If so, I'd like to offer an alternative, that would allow usage even outside of the __autoload function. Namespaces are generally implemented in file based languages (like c, c++, c# etc.), so there isn't an issue with clearing out imported namespaces when a file ends - but since (let me know if this is an incorrect assumption) PHP is an inline based interpreter - it would make sense to have a way to remove namespaces after they have been imported. So the first suggestion is to add an unimport (export?) function that would do just that - remove imported classes (or functions/vars, etc.) from the current (or global?) scope. This functionality combined with the get_imported_namespaces function would allow users to emulate file based namespaces from within the __autoload function, while allowing them to use the standard import statement from within class files. Here is a crude sudo code (that incorrectly assumes import and unimport take a string as an argument) example of an __autoload function that does that: function __autoload($classname) { // class name figuring out code goes here ... // store current namespaces $current_namespaces = get_imported_namespaces(); // remove all current namespaces foreach ($current_namespaces as $namespace_name) { unimport($namespace_name); } // include the class file require_once(...$classname); // remove all namespaces imported from the class file $new_namespaces = get_imported_namespaces(); foreach ($new_namespaces) { unimport($namespace_name); } // reimport the $current_namespaces from the array foreach ($current_namespaces as $namespace_name) { import($namespace_name); } } The addition of two new functions - clear_all_namespaces() and import_namespaces() (or reimport_namespaces, restore_namespaces, etc.) could help clean that up a bit. The example would then look like this: function __autoload($classname) { // class name figuring out code goes here ... // store current namespaces $current_namespaces = get_imported_namespaces(); // remove all current namespaces clear_all_namespaces(); // include the class file require_once(...$classname); // remove all namespaces imported from the class file clear_all_namespaces(); // reimport $current_namespaces from the array restore_namespaces($current_namespaces); } You can see from the example, how this would work inline, just as well as within the __autoload function. Am I completely nuts here? What do you think? Kevin N. PS You could even wrap all those Namespace manipulation methods into a class (initial attempt): Jessie Hernandez wrote: > Kevin, > > Just to make sure, you can get the latest patch from > http://www.zend.com/zend/week/pat/pat44.txt. For documentation, please > refer to this post: http://news.php.net/php.internals/17484. > > Let me know if you have any questions or if you still cannot get the patch > to compile (I wrote the patch against a 5.1 CVS version some months ago, > maybe it doesn't apply cleanly anymore, haven't tried). > > > Regards, > > Jessie Hernandez > > > Kevin Newman wrote: > > >> Hello, >> >> I have been trying to compile PHP with the namespaces patch, but have >> been completely unable to find the time after an initial attempt failed >> (I'm compiling on windows). So I just wanted to know what methods this >> patch provides, if it does at all. Does it support import for example? >> If so, is there any documentation on the methods the patch provides? >> >> Thanks, >> >> Kevin N. >> > >