Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31807 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86014 invoked by uid 1010); 21 Aug 2007 19:07:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 85997 invoked from network); 21 Aug 2007 19:07:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2007 19:07:40 -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 38.99.98.18 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 38.99.98.18 beast.bluga.net Linux 2.6 Received: from [38.99.98.18] ([38.99.98.18:55941] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/62-05248-9F73BC64 for ; Tue, 21 Aug 2007 15:07:39 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 2273AC0DD2A; Tue, 21 Aug 2007 12:07:31 -0700 (MST) Received: from [192.168.0.106] (CPE-76-84-1-170.neb.res.rr.com [76.84.1.170]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id 98602C0DD29; Tue, 21 Aug 2007 12:07:30 -0700 (MST) Message-ID: <46CB3882.7090408@chiaraquartet.net> Date: Tue, 21 Aug 2007 14:09:54 -0500 User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: Stanislav Malyshev CC: internals@lists.php.net References: <46C9F217.8040804@chiaraquartet.net> <200708210039.26755.larry@garfieldtech.com> <46CA7EBF.20909@zend.com> In-Reply-To: <46CA7EBF.20909@zend.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: [PHP-DEV] [PATCH] allowing multiple namespaces per file plusnamespaces with brackets From: greg@chiaraquartet.net (Gregory Beaver) Stanislav Malyshev wrote: >> What happens if you mix them? >> > >> namespace foo { >> class Bar { >> ... >> } >> } >> ?> > > That's not the fun yet. This is: > > namespace baz; > > namespace foo { ...whatever... } > > class bar {} > > ?> If by fun you mean "Fatal error: Namespace cannot be declared twice (without brackets) or nested within brackets in ..." To clarify, the patch works as follows: when namespace baz; is encountered, CG(current_namespace) is set to a non-NULL zstr (name->u.constant). Later on, when you try to namespace foo {}, this check fails: if (CG(current_namespace)) { zend_error(E_COMPILE_ERROR, "Namespace cannot be declared twice (without brackets) or nested within brackets"); } In other words, if there is a current namespace present, you can't declare another or redeclare. This code also fails with the same E_COMPILE_ERROR above (and is one of the new tests in the patch): > Now, is bar in namespace baz or not? I guess it is, otherwise it stops > making any sense. So now when you see in the code it says "class bar" > what do you do to know which namespace it is? Right, you go up to the > code, counting closing and open brackets and hoping you didn't miss any > and try to figure out if it's that main namespace or one of the other > ones. Now next question - how ones in namespace foo are supposed to call > class bar? They'd have to call it by full name, baz::bar, right? Welcome > back, long names. But wait, we could use an import, right? So now we'd > have block-local imports. And we'd have to track them per > namespace-block. BTW, what about imports in baz - are they active in > foo? What if baz wants to talk to class in foo - should it import it? > And BTW - how the patch solves it - I didn't read all of it, but not > sure it does it correctly. > >> Would the compiler have a heart attack if someone did: >> >> > namespace foo { >> namespace baz { >> class Bar { ... } >> } >> } >> ?> > > This syntax implies that baz has access to names in foo. The separate > syntax doesn't. But that's only part of the story - remember the > names/imports story above? Now take that and make it unlimited depth > stack, since you'd have to track everything on *each* nesting level > separately. I wouldn't want to open this can of worms. That'd produce > messy engine and messy code. I don't want to open this can of worms either, and so I didn't. :) Greg