Hi,
Look into th following concept...
In addition to existing syntax I propose to allow one file contain several
namespaces but nothing except namespaces.
The namespaces declarations in such files will contains brackets and may
omit namespace name, that assume global namespace. No nested namespaces are
allowed.
So we will have three types of files:
1) PHP files without namespaces
<?php
import A as X;
function foo() {}
?>
2) PHP files with namespaces
<?php
namespace B;
Import A as X;
function foo() {}
?>
3) Container for multiple namespaces (this is the new one)
This type of file must start from namespace declaration with brackets, must
contain only namespace declaration with brackets, and must not have any code
between or after namespace declarations.
The following example is a concatenation of files from previous examples
<?php
namespace {
import A as X;
function foo() {}
}
namespace B {
import A as Z;
function foo() {}
}
?>
You may always collect files of types (1), (2) and (3) into one file of type
(3) using the following rules:
- file that doesn't start from namespace declaration is wrapped into
namespace declaration with bracket and without name
- file that starts from namespace declaration without brackets is converted
into declaration with brackets
- file that starts from namespace declaration with brackets is used without
modifications
Note that in one file we can have several namespace declarations with the
same name (or without name) and each such declaration uses it's own import
list that doesn't affect other declarations (even with the same name).
Nested namespace declarations are not allowed.
From my point of view this concept completely solves the problem, consistent
and doesn't make any mess with import.
If we came into agreement, I'll implement it.
Thanks. Dmitry.
> > -----Original Message-----
> > From: Gregory Beaver [mailto:greg@chiaraquartet.net]
> > Sent: Tuesday, September 11, 2007 12:10 AM
> > To: Stanislav Malyshev
> > Cc: Dmitry Stogov
> > Subject: Re: multi-namespace patch
> >
> >
> > Stanislav Malyshev wrote:
>> > > I have another question regarding this:
>> > >
>> > > If we allow multiple namespaces per file, but disallow
> > having global
>> > > scope for it (i.e. file can have 1 or more namespaces, but
> > it should
>> > > either start with namespace or not have namespace at all) - do you
>> > > think it would be OK for PEAR/Doctrine/etc. people?
> > That is how my patch works. The problem Dmitry pointed out
> > is that we then can't have non-namespaced code mix with
> > namespaced code, but this would not be an issue for PEAR
> > code, as we would use namespace in every file (mandated by
> > coding standards)
> >
> > It would mean that single large files would contain only
> > library code - good coding practice if you ask me.
> >
> > How did the lab tests go, were you able to verify my benchmarks?
> >
> > Greg
> >