Re: Namespace resolution rules has been changed?

From: Date: Mon, 10 Nov 2008 21:13:28 +0000
Subject: Re: Namespace resolution rules has been changed?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-41839@lists.php.net to get a copy of this message
Jaroslav Hanslík wrote: > David Grudl napsal(a): >> Hello! >> >> This code leads to fatal error: Class 'Nette\Loaders\Nette\Object'. Is >> it a bug in current implementation or namespace resolution rules has >> been changed? >> >> namespace Nette; >> >> class Object >> >> {} >> >> namespace Nette\Loaders; >> >> class AutoLoader extends Nette\Object >> >> {} >> >> $obj = new AutoLoader; >> >> >> >> Thank you, >> David Grudl > > I'm maybe wrong but I think that namespace resolution rules has been > changed. This should work: > > namespace Nette\Loaders; > > class AutoLoader extends \Nette\Object > {} Hi, The resolution rules have changed in that way. The reason was an inconsistency: <?php // Autoload extends Sub\Object class Autoloader extends Sub\Object {} // Another extends Object class Another extends Object {} ?> versus this code: <?php namespace Nette; // Nette\Autoload extends Sub\Object class Autoloader extends Sub\Object {} // Nette\Another extends Nette\Object class Another extends Object {} ?> The problem was that it isn't immediately clear why we would consider "Sub\Object" to be the same as "\Sub\Object", but "Object" to be different from "\Object" inside a namespace context, but the same outside a namespace context. This is an important thing for developers of namespaced code to realize. The docs have been updated in my personal checkout of php-doc, and I am revising them to make them clearer, and also waiting on a few other details to make it into CVS before committing. Thanks, Greg

« previous php.internals (#41839) next »