Php singleton calls a call in autoloader class twice

I created an autoloader class that works as intended, but I noticed strange behavior. When I repeat the results of the found classes that are passed to the method that processes the function spl_autoload_register(). I see that I have doubles. For example, if a script call is called twice, but because it is a singleton, in my case the data builds 2 arrays.

I use this method to create my singleton

public static function init()
{
    if (!isset(self::$instance))
        self::$instance = new self();

    return self::$instance;
}

Then I set the constructor to private. I went through each debugging method, trying to see where, apparently, to create a clone by itself.

I suspect that my classes and class in this case are cloned somewhere in the spl_autoload_register () function.

Any help would be appreciated.

+5
source
1

-. , . ? sp_autoload_register (, index.php) . , .

// :

private static $instance = null;

// init

public static function init() {
   if (self::$instance === null) {
     self::$instance = new Autoload();
   }

   return self::$instance;
}
+3

All Articles