我刚刚更改了所有代码以使用__autoload来发现它与joomla自动加载器冲突.在某些情况下,我将我的应用程序与joomla集成到注册用户等.
我发现spl_autoload_register()显然允许许多自动加载器.
我该怎么办?
更新:这是joomla的作用
从/library/loader.php加载此文件
function __autoload($class)
{
if(JLoader::load($class)) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
更新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');
Run Code Online (Sandbox Code Playgroud)
这就是我的自动加载看起来像:
<?php
//IMPORT
function myAutoload($class_name)
{
$path = str_replace('_', '/', $class_name);
include $path . '.php';
}
?>
spl_autoload_register('myAutoload',false,true);
Run Code Online (Sandbox Code Playgroud)
Mine首先被调用而joomla被调用一秒,然而,app仍然无法找到Joomla类.
更新3:
运行后:
echo "PRE: myAutoload:" . spl_autoload_functions() . "<br />";
spl_autoload_register('myAutoload',false,true);
echo "POST: myAutoload:" . spl_autoload_functions() . "<br />";
Run Code Online (Sandbox Code Playgroud)
和
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 />";
Run Code Online (Sandbox Code Playgroud)
我的输出是:PRE:myAutoload:POST:myAutoload:Array
我不得不将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' );
Run Code Online (Sandbox Code Playgroud)
这是输出
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:
Run Code Online (Sandbox Code Playgroud)
在我包含这些Joomla文件后,我已经知道了
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
Run Code Online (Sandbox Code Playgroud)
spl_autoload_functions()什么都不返回,所以joomla不知何故填满了它.