微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP $GLOBALS缺少$_SERVER

根据http://www.php.net/manual/en/reserved.variables.globals.php

An associative array containing references to all variables which are
currently defined in the global scope of the script.

因此,以下代码必须显示$GLOBALS var具有_SERVER,_ ENV(如果在PHP.ini中的variables_order中启用它)和_REQUEST键:

var_dump($GLOBALS); 

结果是:

>在Nginx PHP-fpm下:缺少_SERVER,_ ENV,_REQUEST
>在cli下:缺少_ENV,_REQUEST

嗯..也许在这个行为的文档中有smth?我查看了每个变量的每个页面

> _SERVER:http://www.php.net/manual/en/reserved.variables.server.php
> _ENV:http://www.php.net/manual/en/reserved.variables.request.php
> _REQUEST:http://www.php.net/manual/en/reserved.variables.request.php

我没有发现过这种行为.它为什么这样?

我已经使用debian软件包从http://www.dotdeb.org/ repo安装了PHP(没有手动编译)…目前正在使用Nginx PHP5-fpm运行.
这是一个PHP bug吗?

解决方法:

我在PHP.net网站上创建了一个bug,PHP团队回答:https://bugs.php.net/bug.php?id=65223

摘要

This is not a bug. super-globals (aka. auto globals) are not added
to symbol tables by default for performance reasons unless the parser
sees need. i.e.

<?PHP $_SERVER; print_r($GLOBALS); ?>

will list it. You can also control this using auto_globals_jit in
PHP.ini:
07001

谢谢PHP团队所以回答这么快!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐