Re: [PATCH] bracketed namespace, unset import, removal of namespace blah;

From: Date: Wed, 22 Aug 2007 23:42:14 +0000
Subject: Re: [PATCH] bracketed namespace, unset import, removal of namespace blah;
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-31860@lists.php.net to get a copy of this message
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: <?php namespace one; class whatever { } other_php_stuff(); ?> file2.php: <?php include 'file1.php'; namespace two; function thingo() {} ?> and literally cut/paste them together to get: <?php namespace one; class whatever { } other_php_stuff(); namespace two; function thingo() {} ?> 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 <?php include 'file2.php'; function thing() {} one::thing(); ?> file2.php: <?php namespace one; function thing() {echo 'hi';} ?> combine erroneously into the "one" namespace <?php namespace one; function thing() {echo 'hi';} function thing() {} one::thing(); ?> 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: <?php namespace one; function thing() {echo 'hi';} namespace __::__main; function thing() {} one::thing(); ?> 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

« previous php.internals (#31860) next »