无法访问 __callStatic 内部的超级全局变量? [英] Can't Access Super Globals Inside __callStatic?

查看:42
本文介绍了无法访问 __callStatic 内部的超级全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在我安装 PHP 5.3.6-13ubuntu3.2 时失败,这让我想知道为什么我无法在此方法中访问 $_SERVER Super Global.

The following code fails on my install of PHP 5.3.6-13ubuntu3.2 which makes me wonder why I can't access the $_SERVER Super Global inside this method.

<?php

header('Content-Type: text/plain');

$method = '_SERVER';
var_dump($$method); // Works fine

class i
{
    public static function __callStatic($method, $args)
    {
        $method = '_SERVER';
        var_dump($$method); // Notice: Undefined variable: _SERVER
    }
}

i::method();

有人知道这里出了什么问题吗?

Anyone know what is wrong here?

推荐答案

如手册所示:

Note: Variable variables

Superglobals cannot be used as variable variables inside functions or class methods. 

(参考)

这篇关于无法访问 __callStatic 内部的超级全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆