Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41800 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98058 invoked from network); 10 Nov 2008 10:50:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Nov 2008 10:50:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:41008] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/2F-13010-CD118194 for ; Mon, 10 Nov 2008 05:50:06 -0500 Received: from MBOERGER-ZRH (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id D27AF11F706; Mon, 10 Nov 2008 11:50:00 +0100 (CET) Date: Mon, 10 Nov 2008 11:49:58 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <501313054.20081110114958@marcus-boerger.de> To: Gregory Beaver CC: internals Mailing List , Dmitry Stogov , Stanislav Malyshev In-Reply-To: <4914AFCA.40307@chiaraquartet.net> References: <4914AFCA.40307@chiaraquartet.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [PATCH] bracketed namespace declarations From: helly@php.net (Marcus Boerger) Hello Gregory, Friday, November 7, 2008, 10:14:50 PM, you wrote: > Hi, > Stas and company decided that they wanted namespaces to have two legal > syntax choices: > 1) single namespace per file: > namespace foo; > ... ?>> > 2) multiple namespaces per file: > namespace foo1 { > } > namespace foo2 { > } ?>> > I've implemented these two syntax options in a patch found at > http://pear.php.net/~greg/bracketed.patch.txt based on earlier work of > Dmitry Stogov. > It turns out there are some tricky details to work out, especially with > regard to importing via use statements. If we just allow global, > un-namespaced code, for instance, we could end up with this mess: For practical reasons outlined by you just again, we already decided not to allow global code after any namespace declaration. That is a namespace can only be followed by another namespace. So the rest of this analysis is irrelevant. marcus > use blah\blah; > $f = new blah; > namespace one { > use foo\bar as blah; > $a = new blah; > } > // what is this? > blah::hi(); ?>> > Technically, you could argue that blah::hi() should resolve to > blah\blah::hi(), but it is very difficult to track and figure out what > "blah" means by eye. Thus, in the patch I implemented, if bracketed > namespace declarations exist, global use statements are not allowed, but > must exist within namespace ns {} brackets. > This creates a problem - how do you combine namespaced and unnamespaced > code? To solve this, I introduced the oft-suggested "namespace {}" > syntax for un-namespaced code. Thus, the above script would become: > namespace { > use blah\blah; > $f = new blah; > } > namespace one { > use foo\bar as blah; > $a = new blah; > } > namespace { > use blah\blah; > blah::hi(); > } ?>> > Another important point is that imports specified by the "use" statement > disappear when we exit a namespace block. This way, it is very easy to > combine un-namespaced code that uses namespaces, and namespaced code. > Also very important to note is that the "namespace {}" syntax is > optional for any code that does not import other things via the "use" > statement - its sole purpose is to provide a clear visual and logical > wrapper within which imports occur. > Thus, this is also legal: > namespace newly\coded\stuff { > class mine { ... } > } > // old stuff here > class PEAR { ... } ?>> > Lastly, if global code does make use of namespaces, but does not import > anything, it can also happily co-exist with bracketed namespace code: > namespace ns { > class mine { ... } > } > $a = new ns\mine; > // and so on ?>> > Thanks, > Greg Best regards, Marcus