Stanislav Malyshev wrote: > Hi! > > Following the feedback from the community, we (mostly me and Dmitry) > tried to find a good model that would allow multiple namespaces per file > without running into too many problems and complications, and would > allow to bundle multiple namespaced files together without > modifications. It looks like it is possible to do, but only under the > following condition: the file can have multiple namespaces, but if the > file has namespaces, then it can have no code outside namespaces. > > For example, this would work: > namespace A; > class X {} > namespace B; > class Y {} > > This would not work: > class X {} > namespace A; > class Y {} > > This would not work either: > require 'foo/bar.php'; > namespace A; > class X {} > > This however would work: > namespace A; > require 'foo/bar.php'; > class X {} > namespace B; > class Y {} > > So, for the people that wanted multiple NS per file, would such solution > work?
Hi, This explanation could be slightly clearer. The most important thing to realize is that allowing multiple namespaces per file is not an attempt to allow a development paradigm where multiple namespaces exist in the same file. Rather, the goal is to allow multiple *files* to be combined into a single file. A benchmark devised by David and modified by me proves that the performance difference between separate files and a single file containing the same stuff is at a minimum 10%, and can be up to 30% difference even with APC and apc.no_stat=1 Allowing multiple namespaces per file should instead be thought of as "allowing several files to be cut/pasted into a single file" and not as a new way to develop in PHP. The proposed syntax is in fact somewhat difficult to read, which discourages development along these lines, but it does make it possible to combine files in a performance-hungry setting. Once the syntax is thought of along these lines, it makes a lot more sense. It's basically one-namespace-per-file but PHP allows you to virtually combine files so that at each namespace declaration, the imports are reset. Greg -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php