gpt4 book ai didi

php - __autoload 灾难 - 与 Joomla 冲突

转载 作者:可可西里 更新时间:2023-11-01 13:58:07 27 4
gpt4 key购买 nike

我刚刚更改了所有代码以使用 __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 />";

我的输出是:上一篇:我的自动加载:发布:我的自动加载:数组

更新 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 以某种方式将其填充。

最佳答案

您应该决定哪个自动加载函数应该优先于另一个,并相应地使用 spl_autoload_register()(查看第三个参数)。 Joomla自动加载功能是如何注册的?

关于php - __autoload 灾难 - 与 Joomla 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3037270/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com