# Name resolution rules

- Thread: https://externals.io/message/37970
- Original archive: https://news-web.php.net/php.internals/37970
- Started by James Dempster on 2008-05-28T16:27:51+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #37970 — James Dempster — 2008-05-28T16:27:51+00:00

URL: https://externals.io/message/37970#37970

I find the namespace resolution rules quite confusing. It's become quite
difficult to tell if I'm calling a static method or a function, or
namespaced static method or namespaced function, and so on. I don't quite
fully understand or appreciated the point of namespaces. If some one could
help me out here.

-- google.php --
<?php
namespace Google;

function search() {
  return 'namespace google search';
}

-- test.php --
<?php
require('google.php');

class Google {
  public static function search() {
    return 'class google search';
  }

  public static function test() {
    return 'class google test';
  }
}

function search() {
  return 'global function search';
}

use Google as Other;

echo '1 '.__FILE__.' #'.__LINE__.' '.search().'<br/>';
echo '2 '.__FILE__.' #'.__LINE__.' '.Google::search().'<br/>';
echo '3 '.__FILE__.' #'.__LINE__.' '.Google::test().'<br/>';
echo '4 '.__FILE__.' #'.__LINE__.' '.Other::test().'<br/>';

1. behaved as I expected it to.
2. didn't do what I thought it should have done, now the class is broken,
but wouldn't though any exception.
3. behaved as I expected it to.
4. wow strange I've managed to rename my class though namespace resolution
rules.

I feel that namespaces are going to cause some big problems. Shouldn't it
wait for PHP6 rather than backport to PHP5.
This is only one of the problems I've come across with namespaces.

Is it going to be possible to get to the google class search method? I find
it terrible that now a name *DOES* clash, but this time with out so much as
an error! I preferred it to highlight the fact that I had a class with the
same name.

Any thoughts?

/James

---

## #37971 — Stan Vassilev | FM — 2008-05-28T16:50:14+00:00

URL: https://externals.io/message/37970#37971 · In reply to: #37970

Hi,

You examples are showing some quite horrible situations with namespaces. 
Agreed, the least thing, an error should be thrown on collision.

Regards,
Stan Vassilev


>I find the namespace resolution rules quite confusing. It's become quite
> difficult to tell if I'm calling a static method or a function, or
> namespaced static method or namespaced function, and so on. I don't quite
> fully understand or appreciated the point of namespaces. If some one could
> help me out here.
>
> -- google.php --
> <?php
> namespace Google;
>
> function search() {
>  return 'namespace google search';
> }
>
> -- test.php --
> <?php
> require('google.php');
>
> class Google {
>  public static function search() {
>    return 'class google search';
>  }
>
>  public static function test() {
>    return 'class google test';
>  }
> }
>
> function search() {
>  return 'global function search';
> }
>
> use Google as Other;
>
> echo '1 '.__FILE__.' #'.__LINE__.' '.search().'<br/>';
> echo '2 '.__FILE__.' #'.__LINE__.' '.Google::search().'<br/>';
> echo '3 '.__FILE__.' #'.__LINE__.' '.Google::test().'<br/>';
> echo '4 '.__FILE__.' #'.__LINE__.' '.Other::test().'<br/>';
>
> 1. behaved as I expected it to.
> 2. didn't do what I thought it should have done, now the class is broken,
> but wouldn't though any exception.
> 3. behaved as I expected it to.
> 4. wow strange I've managed to rename my class though namespace resolution
> rules.
>
> I feel that namespaces are going to cause some big problems. Shouldn't it
> wait for PHP6 rather than backport to PHP5.
> This is only one of the problems I've come across with namespaces.
>
> Is it going to be possible to get to the google class search method? I 
> find
> it terrible that now a name *DOES* clash, but this time with out so much 
> as
> an error! I preferred it to highlight the fact that I had a class with the
> same name.
>
> Any thoughts?
>
> /James
