今天整理代码想使用$GLOBALS['_SERVER']来替代$_SERVER来访问相关的环境变量,总是会报“_SERVER undefined”错误。如下用例:
用例1:
php
用例2:
php
今天整理代码想使用$GLOBALS['_SERVER']来替代$_SERVER来访问相关的环境变量,总是会报“_SERVER undefined”错误。如下用例:
php
php
追根数源,发现PHP5Changelog更新日志的描述:Unordered List ItemImproved Zend Engine, performance tweaks and optimizations Unordered List ItemChanged $GLOBALS into a JIT autoglobal, so it's initialized only if used. (this may affect opcode caches!)www.2cto.com 718 ; When enabled, the SERVER and ENV variables are created when they're first 719 ; used (Just In Time) instead of when the script starts. If these variables 720 ; are not used within a script, having this directive on will result in a 721 ; performance gain. The PHP directives register_globals, register_long_arrays,722 ; and register_argc_argv must be disabled for this directive to have any affect.
723 ; http://php.net/auto-globals-jit 724 auto_globals_jit = On终于弄明白了,PHP5+中在开启auto_globals_jit = On情况下,$_SERVER变量和$_ENV变量不会在脚本启动时就创建,而是会在第一次使用$SERVER和$ENV时才会创建。所以就会出现上述两个用例的情况。
auto_globals_jit setting is also affecting $_REQUEST superglobal in 5.3 It is not explicitly stated in documentation.
至少5.3.13版本中开启auto_globals_jit = On情况下,$_REQUEST也只会在第一次使用时才会创建。
http://www.bkjia.com/PHPjc/477807.html www.bkjia.com true http://www.bkjia.com/PHPjc/477807.html TechArticle今天整理代码想使用$GLOBALS[_SERVER]来替代$_SERVER来访问相关的环境变量,总是会报_SERVER undefined错误。如下用例: 用例1: ?php print_r($GLOBALS)...