Re: AW: [PHP-DEV] Namespace resolution
| From: | David Zülke | Date: | Tue, 11 Dec 2007 22:46:16 +0000 |
| Subject: | Re: AW: [PHP-DEV] Namespace resolution | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33938@lists.php.net to get a copy of this message | ||
Am 11.12.2007 um 23:38 schrieb Stanislav Malyshev:
namespace Name::Space; class Ship { public static function __autoload($className) {A simple if(strpos($className 'My::Namespace::') === 0) will fix that just fine.Fix what? If you write: namespace My::Namespace; function foo() { $a = new DateTime(); } then on each call to foo() autoloader for My::Namespace::DateTime would be called, then it would go to disk and see if there's some file implementing that class, search all include path for it and fail, and only then use internal DateTime. That's not "just fine".
if(strpos($className, 'Name::Space::') === 0) {
// the real deal
}
}
}
...
spl_autoload_register(array('Name::Space::Ship', '__autoload'));
No disk access. And with my suggestion to allow limiting autoloaders to certain namespaces, it would be cut down even further.
- David