SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Why namespace is passed to spl_autoload_register and how can I get rid of it?

    I'm currently doing this but it doesn't look right to me:

    PHP Code:
    spl_autoload_register(function ($class_name){
        
    $class_name str_replace('MyNameSpace\\'''$class_name '.php');

        require 
    $class_name;
    }); 
    Please advise.

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •