php $GLOBALS 显示未定义 "_SERVER"

标签 php arrays variables global

我目前正在开发一个 php 框架,在其中我必须存储 $_SERVER 的变量, $_GET , $_POST等等...

但是当我打电话$GLOBALS["_SERVER"]时我收到未定义索引错误。这是不可能的,因为$_SERVER是预定义变量..对吗?

但是当我打电话$_SERVER时在代码的开头$GLOBALS["_SERVER"]已定义。

你们都错了,我想使用 $GLOBALS 因为以下类,

    class Base_Infrastructure{
    function __construct(){
        $name = '_'.strtoupper(str_replace(__NAMESPACE__."\\","",get_called_class()));
        foreach($GLOBALS[$name] as $i => $v){
            $this->{$i} = $v;
        }
    }
    private function dispatch(){
        $name = '_'.strtoupper(str_replace(__NAMESPACE__."\\","",get_called_class()));
        $GLOBALS[$name] = $this;
        return true;
    }
    function get($name){
        if(isset($this->{$name})&&!empty($this->{$name})){
            return $this->{$name};
        }
    }
    function set($name,$value){
        $this->{$name} = $value;
        $this->dispatch();
        return true;
    }
    function remove($name){
        unset($this->{$name});
        $this->dispatch();
        return true;
    }
}
class Server extends Base_Infrastructure{}
class Post extends Base_Infrastructure{}
class Get extends Base_Infrastructure{}
class Session extends Base_Infrastructure{}
class Cookie extends Base_Infrastructure{
    function set($name,$value){
        $config = $GLOBALS['CONFIG']['cookie'];
        $this->{$name} = $value;
        setcookie($name,$value,time()+$config['expire'],$config['path']);
    }
    function remove($name){
        $config = $GLOBALS['CONFIG']['cookie'];
        unset($this->{$name});
        setcookie($name,null,time()-$config['expire'],$config['path']);
    }
}
class Files extends Base_Infrastructure{}

我认为没有其他办法,除非我一一定义每个类......

最佳答案

我找到了! 问题出在 php.ini 文件中

选项

auto_globals_jit = 开 应为“关闭”

关于php $GLOBALS 显示未定义 "_SERVER",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17384107/

相关文章:

javascript - 如何通过相同键的属性重新排列嵌套数组

java - 将 Java 值发送到网页

Javascript - 如何将匿名方法作为变量调用并访问其属性和方法?

php - 通过 $wpdb 获取所有帖子的元值

PHP parse_ini_file 和 includes 不工作(Ubuntu 桌面 LAMP)

php - 关联到 PHP 中的数值数组

Javascript:将值归因于 id 这段代码有什么问题?

PHP 解析错误 : syntax error, CodeIgniter View 中的文件意外结束

php - 获取具有该行最大值的列和行

javascript - 循环对象和循环数组的嵌套 for 循环