Re: [PATCH] allowing multiple namespaces per file plus namespaces with brackets
| From: | Gregory Beaver | Date: | Tue, 21 Aug 2007 23:15:09 +0000 |
| Subject: | Re: [PATCH] allowing multiple namespaces per file plus namespaces with brackets | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-31819@lists.php.net to get a copy of this message | ||
Stanislav Malyshev wrote:
>> file1.php:
>> <?php
>> namespace foo;
>> class bar {}
>> ?>
>>
>> file2.php:
>> <?php
>> namespace gronk;
>> import foo::bar;
>> class bar {}
>> ?>
>
> The problem is not this code. The problem is this code:
>
> file1.php
> <?php
> namespace foo;
> import otherfoo::bar;
> ?>
>
> file2.php:
> <?php
> namespace gronk;
>
> class bar {}
> ?>
>
> Would start failing too once you merge them in one file, even though
> they worked just fine before.
Right, that's why I was saying expansion of imports would be necessary,
meaning that all references to "bar" would need to be translated to
"otherfoo::bar"
If this is a huge problem, it could be solved by having a separate
import scope within namespace brackets. This is accomplished easily by
storing the existing CG(current_import) in a temp variable,
CG(saved_import), resetting CG(current_import) to NULL to start over at
the namespace declaration, and then restoring the old import list via
CG(current_import) = CG(saved_import) and freeing CG(saved_import).
This would of course mean that top-level import is not the same as
import within a namespace, would that make sense?
I've attached an updated patch to reflect this (it adds 9 lines and a
new test for the approach, ns_046.phpt). Please note that I am not so
sure I like this approach, and I have not deleted the original patch (at
http://pear.php.net/~greg/namespaces.patch.txt).
The new patch is also
at http://pear.php.net/~greg/namespaces_smartimport.patch.txt
Greg