Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32921 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87400 invoked by uid 1010); 23 Oct 2007 00:54:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 87384 invoked from network); 23 Oct 2007 00:54:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Oct 2007 00:54:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.162 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 212.25.124.162 mail.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.162] ([212.25.124.162:26195] helo=mx1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 80/00-21656-A264D174 for ; Mon, 22 Oct 2007 20:54:04 -0400 Received: from us-ex1.zend.com ([192.168.16.5]) by mx1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 23 Oct 2007 02:53:58 +0200 Received: from [192.168.16.91] ([192.168.16.91]) by us-ex1.zend.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 22 Oct 2007 17:53:55 -0700 Message-ID: <471D4623.4090208@zend.com> Date: Mon, 22 Oct 2007 17:53:55 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Chuck Hagenbuch CC: internals@lists.php.net References: <20071019224202.20245u5zry52h5c8@technest.org> <471A6B32.3080401@zend.com> <20071020172658.1680416b83wxgv6s@technest.org> <471A7C88.6090904@zend.com> <20071020184554.69044keujpgfelus@technest.org> <471A8A12.3050407@zend.com> <20071020191948.19935z9hoqcn9c84@technest.org> <471A9049.1020408@zend.com> <20071020194217.98794nbyt3bwrlnk@technest.org> <471AEF26.5000601@zend.com> <20071021105124.85283gxiqqx9zse8@technest.org> <471BA74C.1040103@zend.com> <20071021203755.11105vn0ycds6bs4@technest.org> In-Reply-To: <20071021203755.11105vn0ycds6bs4@technest.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 23 Oct 2007 00:53:55.0171 (UTC) FILETIME=[2FDC2B30:01C8150F] Subject: Re: [PHP-DEV] Order of class resolution with namespaces and autoload From: stas@zend.com (Stanislav Malyshev) > Yes. I think that if you use an unqualified name it should always be > relative to the namespace (and importing internal classes into your > namespace lets you use short names for them, avoiding ::Exception). Unfortunately, there are problems with this solution, since it makes common case harder to implement - internal classes are more frequently used than overridden. It makes harder to convert library code which does not use tricks like overriding system classes - which is on my experience most of the code - you have now to go to almost every file and find all the system classes you have used there and put imports for them. > To me, this is unpredictable because include order changes how otherwise > identical code behaves. It is entirely predictable, and you know the rules that would allow you to predict it. > I can solve this in my case by always writing import Test::Exception;. > However, if I really want to use the builtin Exception class, it seems > like I _must_ type it as ::Exception every time - which is something you > wanted to avoid as well as I. If you really want to use internal class, why you define and include non-internal class with the same name? Moreover, your own proposal above says that's what you have to do - write ::Exception or import. So either you want unqualified internal names to work or you don't? > Other options I tried: > > import Exception; > -> name conflict, which seems correct import Exception is a no-op, so I don't understand how you could have got name conflict. Do you mean "import Test::Exception"? That should work, if it didn't it's a bug. > import Exception as Error; > -> Fatal error: Import name 'Error' conflicts with defined class in > /Users/chuck/Desktop/php namespaces/2.php on line 4 > (this I don't understand) I'm afraid I am missing something since in line 4 of 2.php there's no definition of any class or import. Can you give me full examples of non-working parts? It might be there's some bug in there. > import ::Exception as Error; > -> parse error (can't import a top-level class name that way) Well, we might allow importing global classes, if it's needed. > Therefore, in my mind, in order to write durable code that will not > break no matter what other classes other developers define or import, I > should always prefix builtin classes with ::. Other developers shouldn't define or import classes into your namespace... > Given this, the only difference between how I think things should work > is that I think that, when I have declared a namespace, I should be able > to rely on any short name referring to that namespace or one of my > explicit imports. The key being that _I_ declared that namespace and the Well, I think restricting namespaced code's access to internal classes is not a good idea, since internal classes are rather frequently used. > imports and they will affect only that file, so I am completely in > control of what name means what. You can control it anyway, you just have to be a bit more explicit now. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com