ivwsai
<?php
function test() {
     
$c = 2;
}
$a = 1;
$b = 2;

?>
上边的代码的$a和$b都在$GLOBALS里,与$GLOBALS[\'a\']和$GLOBALS[\'B\']是等价的,但$c 不是,他是函数的私有变量,不在$GLOBALS里,如下可知:
<?php
// 例子2
function test() {
 
$c = 2;
 
$GLOBALS[\'a\'= \'DDD\';

}
$a = 1;
$b = 2;

test();

print $a;//此时输出的是DDD而不是1.
?>

有趣的是:$GLOBALS变量又是$GLOBALS变量的值,你会发现$GLOBALS 下有$GLOBALS,这个$GLOGALS下又有$GLOBALS,这样一直层层不断的套下去,很是有趣。

  
<?php
// 例子3
function test() {
 
$c = 2;
 
$GLOBALS[\'a\'= \'DDD\';

}
$a = 1;
$b = 2;

test();
print_r($GLOBALS[\'GLOBALS\'][\'GLOBALS\'][\'GLOBALS\'][\'GLOBALS\']);

print_r($GLOBALS);

//以上两个打印的结果是一样的
?>




bestmost 2009-02-27 13:53 发表评论

文章来源:http://www.phpweblog.net/fuyongjie/archive/2009/02/27/6354.html

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-06-17
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2023-03-19
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2021-09-13
  • 2022-02-02
  • 2021-06-09
  • 2021-11-02
  • 2022-03-10
相关资源
相似解决方案