使用多个自动加载器PHP

Res*_*had 15 php autoloader

您好我正在尝试使用SILEX微框架和我自己的库充满类,因此我遇到了2个加载器,导致加载器无法加载类的错误..是否有办法同时使用这2个加载器没有收到此错误?

我使用的装载机你可以在下面找到:

    <?php

/*
 * Loader
 */

function my_autoloader($className) 
{
// haal de base dir op.
  $base = dirname(__FILE__);


  // het pad ophalen
  $path = $className;

  // alle paden samenvoegen tot waar ik zijn moet en de phpfile eraan plakken.
  $file = $base . "/lib/" . $path . '.php';       

  // als file bestaat haal op anders error
  if (file_exists($file)) 
  {
      require $file;
  }
  else 
  {
      error_log('Class "' . $className . '" could not be autoloaded');
      throw new Exception('Class "' . $className . '" could not be autoloaded from: ' . $file); 
  }
}

spl_autoload_register('my_autoloader');

?>
Run Code Online (Sandbox Code Playgroud)

silex使用的加载器位于供应商目录中(来自框架本身)

这就是我的文件树的样子:

文件树

Exp*_*lls 36

不要在自动加载器功能中抛出错误. spl_autoload_register允许php按顺序浏览所有注册的自动加载器,但如果你在该过程中间抛出未被捕获的错误,则无法尝试下一个自动加载器.

http://php.net/spl_autoload_register