Joomla - framework.php取消了我的变种

时间:2013-10-01 12:19:54

标签: php joomla unset

我在外部PHP Web应用程序中使用Joomla(1.5.26)身份验证。

我的问题是包含的joomla文件“framework.php”取消了之前定义的任何变量。

// some code
$varfoo = 'toto';

define( '_JEXEC', 1 );
define('JPATH_BASE', $_SERVER['DOCUMENT_ROOT']);
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php');

// authentification code

var_dump($varfoo); // NULL

我可以在定义任何变量之前包含Joomla,但我想知道行为是否正常或者我是否做错了。

谢谢

我制作了一个测试文件

define( '_JEXEC', 1 );
define('JPATH_BASE', $_SERVER['DOCUMENT_ROOT']);
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php');
$varfoo = 'toto';
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php');
var_dump($varfoo); // NULL

1 个答案:

答案 0 :(得分:1)

Joomla 1.5.x清除JRequest::clean()方法libraries/joomla/environment/request.php第486行中的全局变量:

foreach ($GLOBALS as $key => $value)
{
    if ( $key != 'GLOBALS' ) {
        unset ( $GLOBALS [ $key ] );
    }
}

如果你真的需要保留一些全局变量,可以将它们存储在静态类变量中。

class Foo {
    public static $data;
}

Foo::$data = new stdClass();

Foo::$data->bar = 'toto';

require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php');
var_dump(Foo::$data->bar); // 'toto'