我刚刚更改了所有代码以使用 __autoload 发现它与 joomla 自动加载器冲突。在某些情况下,我将我的应用程序与 joomla 集成以注册用户等。
我发现 spl_autoload_register() 显然允许许多自动加载器。
我应该怎么办?
更新:这就是 joomla 所做的
从 /library/loader.php 加载这个文件
function __autoload($class)
{
if(JLoader::load($class)) {
return true;
}
return false;
}
更新 2:
好的,在我加载我调用的 Joomla 库之后
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
//autoloader so that it does not interfere with mine
spl_autoload_register('__autoload');
这是我的自动加载的样子:
<?php
//IMPORT
function myAutoload($class_name)
{
$path = str_replace('_', '/', $class_name);
include $path . '.php';
}
?>
spl_autoload_register('myAutoload',false,true);
我的首先被调用,然后 joomla 被调用,但是,该应用程序仍然找不到 Joomla 类。
更新 3:
运行后:
echo "PRE: myAutoload:" . spl_autoload_functions() . "<br />";
spl_autoload_register('myAutoload',false,true);
echo "POST: myAutoload:" . spl_autoload_functions() . "<br />";
和
echo "PRE: JoomlaAutoLoad:" . spl_autoload_functions() . "<br />";
//autoloader so that it does not interfere with mine
spl_autoload_register('__autoload');
echo "POST: JoomlaAutoLoad:" . spl_autoload_functions() . "<br />";
我的输出是:PRE:myAutoload:POST:myAutoload:Array
更新 4:
我不得不将 Joomla 导入更改为:
require_once ( JPATH_BASE .DS.'libraries'.DS.'loader.php' );
echo "PRE: JoomlaAutoLoad:" . var_dump(spl_autoload_functions()) . "<br />";
//autoloader so that it does not interfere with mine
spl_autoload_register('__autoload');
echo "POST: JoomlaAutoLoad:" . var_dump(spl_autoload_functions()) . "<br />";
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
这是输出
PRE: myAutoload:
array
0 => string 'myAutoload' (length=10)
POST: myAutoload:
array
0 => string 'myAutoload' (length=10)
PRE: JoomlaAutoLoad:
array
0 => string 'myAutoload' (length=10)
1 => string '__autoload' (length=10)
POST: JoomlaAutoLoad:
在我包含这些 Joomla 文件后,我已经解决了
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
spl_autoload_functions() 什么都不返回,所以 joomla 不知何故把它填满了。