暂时禁用自动加载堆栈

时间:2013-07-17 10:24:00

标签: php autoloader

有人可以告诉我是否可以暂时禁用spl_autoloader,然后再启用它,如果是这样,怎么办?或者,如果这是不可能的,有没有办法将自动加载堆栈“拉”到一个临时变量中,这会导致堆栈停用(当它为空时),然后从该变量重新注册所有内容。

1 个答案:

答案 0 :(得分:5)

归功于拥有解决方案的巴特

  

您可以使用spl_autoload_functions来收集函数然后   使用spl_autoload_unregister取消注册它们

我测试了下面的工作:

<?php

$autoloadFuncs = spl_autoload_functions();
var_dump($autoloadFuncs);

foreach($autoloadFuncs as $unregisterFunc)
{
    spl_autoload_unregister($unregisterFunc);
}

// Code goes here that you dont want the auto loader enabled for.

foreach($autoloadFuncs as $registerFunc)
{
    spl_autoload_register($registerFunc);
}
?>