Re: Re: Order of class resolution with namespaces and autoload

From: Date: Sat, 20 Oct 2007 21:28:32 +0000
Subject: Re: Re: Order of class resolution with namespaces and autoload
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-32885@lists.php.net to get a copy of this message
Quoting Stanislav Malyshev <stas@zend.com>:
<?php namespace Test; // explicitly tell PHP that we want Test::Exception to be autoloaded (in essence) import Test::Exception; class Tester { public function fail() {
       throw new Exception();
} } ?>
This is even better than requiring, and makes the intent very clear. I don't think it decreases intuitiveness, on the contrary - from the look of the code it is immediately clear which exception would be used.
Except that it makes it unclear what happens in _other_ files, which is even worse. Once you include the file above, any other file in the Test:: namespace that throws an Exception will throw Test::Exception, not Exception, even if it doesn't import Test::Exception. I think it makes much more sense to import classes that are _outside_ the current namespace. Having to import pieces of your own namespace makes namespaces less useful and intuitive. -chuck

« previous php.internals (#32885) next »