Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40670 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88488 invoked from network); 24 Sep 2008 22:59:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2008 22:59:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 208.83.222.18 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 208.83.222.18 unknown Linux 2.6 Received: from [208.83.222.18] ([208.83.222.18:42004] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/AE-52685-D36CAD84 for ; Wed, 24 Sep 2008 18:59:10 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 4FBECC0E3C6; Wed, 24 Sep 2008 15:58:05 -0700 (MST) Received: from Greg-Beavers-monster.local (unknown [65.119.49.235]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id A85C3C0E3B0; Wed, 24 Sep 2008 15:58:04 -0700 (MST) Message-ID: <48DAC639.2000406@chiaraquartet.net> Date: Wed, 24 Sep 2008 17:59:05 -0500 User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070807) MIME-Version: 1.0 To: Stanislav Malyshev CC: 'PHP Internals' References: <48D7F5EF.3090202@zend.com> In-Reply-To: <48D7F5EF.3090202@zend.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: namespace issues From: greg@chiaraquartet.net (Greg Beaver) Stanislav Malyshev wrote: > Hi! > > On the ZendCon, we (Marcus, Elizabeth, Andi and myself) had a talk about > what we'd like to do with namespaces, and we arrived at the following > conclusions, which we propose to implement in 5.3: > > 1. Allow braces for namespaces. So, the syntax for namespaces will be: > a) namespace foo; > should be first (non-comment) statement in the file, namespace extends > to the end of the file or next namespace declaration. > b) namespace foo {} > can appear anywhere on the top scope (can not be nested). > Mixing both syntaxes in one file is not possible. The semantics of both > syntaxes will be identical. > > 2. Simplify resolution order for classes in the namespace: unqualified > names are resolved this way: > a) check "use" list if the name was defined at "use", follow that > resolution > b) if not, the name resolves to namespace::name > Consequence of this will be that for using internal class inside > namespace one would need to refer to it either as ::Foo or do use ::Foo > prior to its usage. > > 3. Functions will not be allowed inside namespaces. We arrived to > conclusion that they are much more trouble than they're worth, and > summarily we would be better off without them. Most of the functionality > could be easily achieved using static class methods, and the rest may be > emulated with variable function names, etc. I'm happy with #1 although I prefer 1 syntax to rule them all, I can live with this #2 #3 if it also includes removing namespace constants For future post-5.3, functions could be added back in. The ambiguity issue could easily be fixed by having a different scoping resolution operator for namespaced classes vs. namespaced functions/consts. For instance: func(); // namespaced function blah::thing:>func echo blah::thing:>constant; // namespaced constant blah::thing:>constant blah::thing:>$var = 1; // namespaced variable blah::thing:>$var (pure fantasy, but illustrates the point) blah::thing::$var = 1; // namespaced class blah::thing, class variable $var ?> Before anyone gets all hyper, my point is *not* to introduce :>, but to explain that it is in fact technically feasible to extend the definition of namespaces later to add support for non-class elements and it would work just fine. It is, however, not going to be possible to do this post-5.3 without the change above. Note that we have a different operator for dereferencing static class members (::) versus object members (->) for the reason that the thing being dereferenced is different. Namespaces are in fact different from classes, so the problem with the current implementation is that the same operator (::) used for both means we cannot allow any ambiguity between namespace contents and class contents. As long as classes cannot contain other classes: then :: can be used for both namespace operator and static class operator if functions/constants are removed from namespaces. Greg