# Namespace resolution rules has been changed?

- Thread: https://externals.io/message/41968
- Original archive: https://news-web.php.net/php.internals/41968
- Started by David Grudl on 2008-11-17T10:57:50+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

---

## #41968 — David Grudl — 2008-11-17T10:57:50+00:00

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

Try to answer the question: what is the $obj instance of?

namespace foo;
$obj = $factory->loadClass('bar\class');

-------
$factory is implemented cca this way:

namespace ?;

class Factory
{
    function loadClass($class) {
       return new $class;
    }
}


With absolute FQN is the answer evident. With relative FQN it is very 
esoteric.

With relative FQN developers will have to implement "save" loadClass() 
this way:

function  loadClass($class)
{
     if (strpos($class, '\\') !== `FALSE` && strncmp($class, '\\', 1)) {
        $class = '\\' . $class;
     }
     return new $class;
}

OMG

David Grudl

---

## #41970 — Gregory Beaver — 2008-11-17T11:10:47+00:00

URL: https://externals.io/message/41968#41970 · In reply to: #41968

David Grudl wrote:
> Try to answer the question: what is the $obj instance of?
> 
> namespace foo;
> $obj = $factory->loadClass('bar\class');

bar\class

dynamic class names are always FQN.

Greg
