Re: solving the namespace conflict issues between function/static method class constant/ns constant
| From: | Derick Rethans | Date: | Wed, 01 Oct 2008 16:33:04 +0000 |
| Subject: | Re: solving the namespace conflict issues between function/static method class constant/ns constant | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40821@lists.php.net to get a copy of this message | ||
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?
regards,
Derick
--
HEAD before 5_3!: http://tinyurl.com/6d2esb
http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org