Re: solving the namespace conflict issues between function/static method class constant/ns constant
| From: | Jochem Maas | Date: | Wed, 01 Oct 2008 16:56:09 +0000 |
| Subject: | Re: solving the namespace conflict issues between function/static method class constant/ns constant | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40822@lists.php.net to get a copy of this message | ||
Derick Rethans schreef:
> On Fri, 19 Sep 2008, Greg Beaver wrote:
>
>> Hi all,
>>
>> There is a problem in the namespace implementation. This code demonstrates
>> the issue:
>>
>> code.inc:
>> <?php
>> namespace foo;
>> class test {
>> const my = 1;
>> static function bar(){}
>> }
>>
>> namespace foo::test;
>> const my = 2;
>> function bar(){}
>> ?>
>>
>> main.php:
>> <?php
>> include 'code.inc';
>> foo::test::bar(); // always calls namespace function
>> call_user_func(array('foo::test', 'bar')); // the only way to call
>> static
>> method
>> echo foo::test::my; // always 2
>> $a = new foo::test;
>> echo $a::my; // the only way to access foo::test::my
>> ?>
>>
>> There are 5 ways to solve this:
>>
>> 1) document it and hope no one uses it [this is the current strategy, minus
>> the documentation part]
>> 2) add a fatal error on conflicting names.
>
> Uh, if we don't have functions in namespaces, then the second "function
> bar(){}" would define the bar function in the global scope only and not
> as part of the foo::test namespace... so one more reason to remove
> functions (and constants) from namespaces?
I don't follow the logic. if we don't have functions in namespaces the second
"function bar(){}" would be a parse error, no?
>
> regards,
> Derick