Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40495 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6467 invoked from network); 13 Sep 2008 00:21:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Sep 2008 00:21:50 -0000 X-Host-Fingerprint: 68.112.148.14 68-112-148-14.dhcp.stcd.mn.charter.com Received: from [68.112.148.14] ([68.112.148.14:25926] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 79/F0-00143-D970BC84 for ; Fri, 12 Sep 2008 20:21:50 -0400 Message-ID: <79.F0.00143.D970BC84@pb1.pair.com> To: internals@lists.php.net Date: Fri, 12 Sep 2008 19:21:47 -0500 User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.112.148.14 Subject: Re: Scoping of "use" statements and a strategy for 5.3/6.0 release of namespace From: rpanning@gmail.com (Ryan Panning) Stan Vassilev | FM wrote: > Hi, > > Multiple namespaces per file were introduced to allow certain workflows in PEAR and frameworks like Symphony which can combine multiple classes and namespaces in a single package. > > They work like this: > > > namespace X; > > ... > > namespace Y; > > ... > > > The problem is, no one thought of scoping "use" statements, so now those merged files share their "use" imports, thus breaking all the code where collisions occur. > > Also we have the problems with name resolution of internal vs user classes and autoloaders, discussed here. > > And we also have the non-intuitive differentiation between resolving functions/classes/constant which will most likely lead people to believe functions/constants aren't supported in any way in namespaces (if they try, and it doesn't work, they won't try second time). > > Which leads me to the following proposal: > > For PHP 5.3 we introduce namespaces with a very limited "safe" set of barebones features, that we won't regret later for releasing and having to modify in a non-BC way. It'll let people start porting their code and be ready for the full featureset later on, which will be a proper superset of the 5.3 release: > > 1) We disable support for multiple namespaces per file as it is, as it can't be used without ability to scope "use" statements as well. > > 2) We remove the statement "use" (regarding namespaces, not regarding closures), until we get more feedback from the community on the exact preferred resolution algorithms, and more thought is put to this. > > For PHP 5.4 or 6: > > 1) Introduce file-level "use" statements with same syntax as now, but modified resolution rules based on further discussion and feedback. And if someone is about to say "we had plenty of discussion", well it's apparent we didn't have enough given all the problems facing namespaces right now, or maybe not enough of the constructive type of discussion. > > 2) Introduce ability to scope "use" and "namespace" statements with curly brackets, so that multiple files can be safely merged without changing intent (all file-level namespace can be converted with curly brackets, and the existing curly bracket ones don't need to be converted), example: > > namespace X { > use Y as Z { > ... > } > } > > namespace Y { > use X as Z { > ... > } > } > > > Waiting for your feedback... > > Regards, > Stan Vassilev Again, some more 2 cents from me. I'm not sure if this has already been decided but I agree with multiple namespaces per file. Just seems like a good practice for large frameworks. And I'm leaning towards +1 on NON-brackets for namespaces. With multiple namespace declarations in one file the way it is now, brackets seem un-needed. As far as the scope of "use" in a multi-namespace file: Considering that in a multi-namespace file, a namespace declaration ends the previous namespace and begins the new one. Can the scope of the "use" statement be whatever namespace declaration it is in? Ex: There are a couple benefits with this way: 1. If multiple namespaces have the exact same use statements, they won't conflict. Because the scope of use only applies the current namespace declaration. 2. Merging multiple files is easier. Before the files are merged, the developer would probably be testing their framework. This means that the separate files have use statements in each one. When merging them all together, the use statements won't conflict. I agree that if use does not have a scope, it would become confusing. If there wasn't, what would happen when there are two exact same use statements. Or, if use statements point to different namespaces but have the same name. Another question when merging multiple files, is it ok to declare the same namespace multiple times? If I were to merge files, I would just append them all to one file.