Welcome! Log In Create A New Profile

Advanced

[PHP-DEV] Re: Namespace resolution rules has been changed?

Posted by David Grudl 
David Grudl
[PHP-DEV] Re: Namespace resolution rules has been changed?
November 17, 2008 12:00PM
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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Gregory Beaver
Re: [PHP-DEV] Re: Namespace resolution rules has been changed?
November 17, 2008 12:10PM
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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login