Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:32888 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73664 invoked by uid 1010); 20 Oct 2007 22:24:38 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 73649 invoked from network); 20 Oct 2007 22:24:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Oct 2007 22:24:38 -0000 Authentication-Results: pb1.pair.com header.from=chuck@horde.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chuck@horde.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain horde.org designates 66.92.78.250 as permitted sender) X-PHP-List-Original-Sender: chuck@horde.org X-Host-Fingerprint: 66.92.78.250 dsl092-078-250.bos1.dsl.speakeasy.net Received: from [66.92.78.250] ([66.92.78.250:40383] helo=technest.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/6B-03598-5208A174 for ; Sat, 20 Oct 2007 18:24:38 -0400 Received: by technest.org (Postfix, from userid 33) id 7AF3A7F00D; Sat, 20 Oct 2007 18:24:34 -0400 (EDT) Received: from tatiana (tatiana [192.168.1.2]) by technest.org (Horde Framework) with HTTP; Sat, 20 Oct 2007 18:24:34 -0400 Message-ID: <20071020182434.512034p03a24phes@technest.org> Date: Sat, 20 Oct 2007 18:24:34 -0400 To: Stanislav Malyshev Cc: Gregory Beaver , internals@lists.php.net References: <20071019224202.20245u5zry52h5c8@technest.org> <47196F1A.80400@chiaraquartet.net> <471A6BC6.3090608@zend.com> <20071020172832.338919lgcfp4v1us@technest.org> <471A7932.9040707@zend.com> In-Reply-To: <471A7932.9040707@zend.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable User-Agent: Internet Messaging Program (IMP) H3 (4.2-cvs) Subject: Re: [PHP-DEV] Re: Order of class resolution with namespaces and autoload From: chuck@horde.org (Chuck Hagenbuch) Quoting Stanislav Malyshev : >> Except that it makes it unclear what happens in _other_ files, which is > > In other files you specify what happens to other files. > >> even worse. Once you include the file above, any other file in the =20 >> Test:: namespace that throws an Exception will throw =20 >> Test::Exception, not Exception, even if it doesn't import =20 >> Test::Exception. > > I'm afraid I don't understand. Regardless of what you include where, =20 > the name resolution for the file is defined by the code and imports =20 > in this file. Since that file does not define test::exception, it =20 > would not influence resolution of any file it is included in. This isn't true with the current implementation. Consider these four files: test_exception.php: ------------------- > I think it makes much more sense to import classes that are =20 >> _outside_ the current namespace. Having to import pieces of your =20 >> own namespace makes namespaces less useful and intuitive. > > Import is just a way to write names shorter. Thus, you can employ it =20 > to achieve different goals. This is true. The goal I am looking at is making sure that when I use =20 a namespace I have full control over the things inside my namespace. =20 The way things work right now I either need to list every single class =20 in my namespace in every file of that namespace - which is going to be =20 a bit burdensome, and seems like a discouragement from using =20 namespaces - or I am at the mercy of PHP adding a new class that might =20 suddenly take the place of one of my namespace classes. Or presumably =20 someone who used my code could include a different librry that =20 suddenly overrode one of my classes with a global class. I understand the argument that namespaces should require minimal =20 change to other code, but I think that PHP should encourage people to =20 think a little bit when putting "namespace Foo" at the top of a file. =20 That should really mean, in my opinion, that everything in that file =20 is relative to that namespace by default. It's not hard to then import the global bit you want. Think about how variable scope works in PHP. The way I am proposing =20 namespaces to work, they would match scope. You would have: $GLOBALS =3D> :: - if you want to reference something from global =20 scope without aliasing it, you can reference it explicitly global $variable =3D> this is like import, but import lets you alias the =20 name as well, for using things from global scope but making them look =20 like they are local Everything else is in the local scope. I don't have a grand theory of why variable scope and class scope =20 should match, but it seems reasonable. The main thing is that I think that the sort of people who are going =20 to want to use namespaces are going to want namespaces to be as =20 self-contained as possible, and that means explicitly importing =20 external bits, not internal bits. Sincerely, -chuck