Re: Namespace resolution rules has been changed?
| From: | David Grudl | Date: | Mon, 17 Nov 2008 10:57:50 +0000 |
| Subject: | Re: Namespace resolution rules has been changed? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-41968@lists.php.net to get a copy of this message | ||
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