I'm currently doing this but it doesn't look right to me:
Please advise.PHP Code:spl_autoload_register(function ($class_name){
$class_name = str_replace('MyNameSpace\\', '', $class_name . '.php');
require $class_name;
});
| SitePoint Sponsor |
I'm currently doing this but it doesn't look right to me:
Please advise.PHP Code:spl_autoload_register(function ($class_name){
$class_name = str_replace('MyNameSpace\\', '', $class_name . '.php');
require $class_name;
});
The namespace is passed so you can apply whatever logic you need to load the required librar(y|ies), and what you're doing looks okay to me (ie. applying your own specific logic). My advice, take a look at PSR-0 and see how the implementation differs to your own.
Anthony.
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
Bookmarks