Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31860 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20438 invoked by uid 1010); 22 Aug 2007 23:40:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 20421 invoked from network); 22 Aug 2007 23:40:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Aug 2007 23:40:04 -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 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:34672] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/30-18325-D49CCC64 for ; Wed, 22 Aug 2007 19:40:00 -0400 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id C70C6C0D3A1; Wed, 22 Aug 2007 16:39:49 -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 8922EC0D3A0; Wed, 22 Aug 2007 16:39:48 -0700 (MST) Message-ID: <46CCC9D6.8060106@chiaraquartet.net> Date: Wed, 22 Aug 2007 18:42:14 -0500 User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: Stanislav Malyshev CC: internals Mailing List , Dmitry Stogov References: <46CBA2B6.2010600@chiaraquartet.net> <46CC637B.9070500@zend.com> In-Reply-To: <46CC637B.9070500@zend.com> Content-Type: multipart/mixed; boundary="------------070605060807090101040605" X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: [PHP-DEV] [PATCH] bracketed namespace, unset import, removal of namespace blah; From: greg@chiaraquartet.net (Gregory Beaver) --------------070605060807090101040605 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Stanislav Malyshev wrote: >> 1) adds "unset import" syntax for declaring a namespace to have local >> import scope (it does NOT affect variable scope or the global >> class/function table) > > I don't like it. What's "unset import"? Seems to be very artificial > concept. > >> be as intuitive as possible. Having a separate scope by default for >> import that does not inherit from the global scope is not very >> intuitive. > > Yep, it isn't. But it's the only concept that we saw so far that is > consistent and logical. Hi, The purpose of all my patches is to make it possible to combine multiple namespaces into a single file. It looks like namespace {} syntax introduces much more trouble than it is worth. As such, since my only goal is to be able to combine multiple files into a single file, the attached patch basically allows you to take these two files: file1.php: file2.php: and literally cut/paste them together to get: The patch acts as if each namespace were a separate file with respect to import statements as well as class/function declarations. The only limitation is that a situation like so: file1.php file2.php: combine erroneously into the "one" namespace The solution, which is a simple one, is upon combining to insert a bogus namespace declaration for the contents of file1.php, and is a simple one for a build tool or a developer to accomplish. Developers who would combine files together would need to scan for include statements if autoload was not used, and scanning for missing namespace declarations is trivial in this situation: Can we agree on this patch? It preserves the original simple syntax that I like so much (no brackets), solves the import scoping problem, and allows combining files without removing the structure in namespacing. It also discourages using multiple namespaces per file, as the ease of using import across namespace declarations is gone. Finally, it preserves the need of the first namespace declaration being at the top of the file, another appealing feature of the original syntax. The attached patch is also at http://pear.php.net/~greg/multiple_namespaces.patch.txt Thanks for your patience, Greg --------------070605060807090101040605 Content-Type: text/plain; name="multiple_namespace.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="multiple_namespace.patch.txt" ? multiple_namespace.patch.txt ? namespace.patch.txt ? namespace_brackets_unsetimport.patch.txt ? namespace_smartimport.patch.txt Index: Zend/zend_compile.c =================================================================== RCS file: /repository/ZendEngine2/zend_compile.c,v retrieving revision 1.764 diff -u -r1.764 zend_compile.c --- Zend/zend_compile.c 22 Aug 2007 07:39:37 -0000 1.764 +++ Zend/zend_compile.c 22 Aug 2007 23:15:02 -0000 @@ -4966,11 +4966,8 @@ unsigned int lcname_len; zstr lcname; - if (CG(active_op_array)->last > 0) { - zend_error(E_COMPILE_ERROR, "Namespace declaration statement has to be the very first statement in the script"); - } - if (CG(current_namespace)) { - zend_error(E_COMPILE_ERROR, "Namespace cannot be declared twice"); + if (!CG(current_namespace) && CG(active_op_array)->last > 0) { + zend_error(E_COMPILE_ERROR, "First namespace declaration statement has to be the first statement in the script"); } lcname = zend_u_str_case_fold(Z_TYPE(name->u.constant), Z_UNIVAL(name->u.constant), Z_UNILEN(name->u.constant), 0, &lcname_len); if (((lcname_len == sizeof("self")-1) && @@ -4981,6 +4978,16 @@ } efree(lcname.v); + if (CG(current_namespace)) { + zval_dtor(CG(current_namespace)); + efree(CG(current_namespace)); + } + if (CG(current_import)) { + zend_hash_destroy(CG(current_import)); + efree(CG(current_import)); + } + CG(current_import) = NULL; + ALLOC_ZVAL(CG(current_namespace)); *CG(current_namespace) = name->u.constant; } Index: Zend/tests/ns_039.phpt =================================================================== RCS file: Zend/tests/ns_039.phpt diff -N Zend/tests/ns_039.phpt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Zend/tests/ns_039.phpt 22 Aug 2007 23:15:03 -0000 @@ -0,0 +1,35 @@ +--TEST-- +039: two namespace declarations +--FILE-- +