Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41766 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63840 invoked from network); 7 Nov 2008 21:14:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Nov 2008 21:14:31 -0000 Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 74.125.78.26 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 74.125.78.26 ey-out-2122.google.com Received: from [74.125.78.26] ([74.125.78.26:58448] helo=ey-out-2122.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/1F-02726-6BFA4194 for ; Fri, 07 Nov 2008 16:14:31 -0500 Received: by ey-out-2122.google.com with SMTP id 5so564499eyj.59 for ; Fri, 07 Nov 2008 13:14:27 -0800 (PST) Received: by 10.210.23.3 with SMTP id 3mr734827ebw.9.1226092467605; Fri, 07 Nov 2008 13:14:27 -0800 (PST) Received: from ?192.168.0.106? ([76.84.4.101]) by mx.google.com with ESMTPS id k5sm2472315nfd.22.2008.11.07.13.14.25 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 07 Nov 2008 13:14:26 -0800 (PST) Message-ID: <4914AFCA.40307@chiaraquartet.net> Date: Fri, 07 Nov 2008 15:14:50 -0600 User-Agent: Thunderbird 2.0.0.17 (X11/20080925) MIME-Version: 1.0 To: internals Mailing List , Dmitry Stogov , Stanislav Malyshev Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [PATCH] bracketed namespace declarations From: greg@chiaraquartet.net (Gregory Beaver) Hi, Stas and company decided that they wanted namespaces to have two legal syntax choices: 1) single namespace per file: 2) multiple namespaces per file: 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: 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: 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: Lastly, if global code does make use of namespaces, but does not import anything, it can also happily co-exist with bracketed namespace code: Thanks, Greg