简体   繁体   English

PHP $ GLOBALS缺少$ _SERVER

[英]PHP $GLOBALS missing $_SERVER

According to http://www.php.net/manual/en/reserved.variables.globals.php : 根据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. 一个关联数组,包含对当前在脚本全局范围内定义的所有变量的引用。

So, following code must display that $GLOBALS var has _SERVER , _ENV (if it is enabled in variables_order in php.ini) and _REQUEST keys: 因此,以下代码必须显示$ GLOBALS var具有_SERVER_SERVER _ENV (如果在php.ini中的variables_order中启用它)和_REQUEST键:

var_dump($GLOBALS); 

The result is: 结果是:

  • Under nginx + php-fpm: missing _SERVER , _ENV , _REQUEST 在nginx + php-fpm下:缺少_SERVER_SERVER _ENV_REQUEST
  • Under cli: missing _ENV , _REQUEST 在cli下:缺少_ENV_REQUEST

Hmm.. perhaps there is smth in docs about this behavior? 嗯..也许在这个行为的文档中有smth? I've looked through every page for each variable: 我查看了每个变量的每个页面:

And i have found no mentions about such behaviour. 我没有发现过这种行为。 Why it works like that? 它为什么这样?

I have installed php using debian package from http://www.dotdeb.org/ repo (nothing was compiled manually)... Currently running with nginx + php5-fpm. 我已经使用http://www.dotdeb.org/ repo的debian软件包安装了php(没有手动编译)...目前运行的是nginx + php5-fpm。 Is that a php bug? 这是一个php bug吗?

I've created a bug on php.net website, and php team answered: https://bugs.php.net/bug.php?id=65223 我在php.net网站上创建了一个bug,php团队回答: https ://bugs.php.net/bug.php?id = 65223

Summary: 摘要:

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. 出于性能原因,默认情况下,超级全局变量(也称为自动全局变量)不会添加到符号表中,除非解析器看到需要。 ie

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

will list it. 会列出来的。 You can also control this using auto_globals_jit in php.ini: http://www.php.net/manual/en/ini.core.php#ini.auto-globals-jit 您也可以使用php.ini中的auto_globals_jit来控制它: http ://www.php.net/manual/en/ini.core.php#ini.auto-globals-jit

Thanks php team so answer so fast! 谢谢php团队所以回答这么快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM