PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<Cookies从 PHP/FI 2 移植到 PHP 3>
Last updated: Mon, 16 Jul 2012

处理全局变量

在 PHP 3 和 PHP 4 早些版本中处理全局变量的重心放在了易用上,而现在,焦点放到了如何更安全的处理它们上。在 PHP 3 中下面的代码工作正常,但是 PHP 4 中就要使用 unset($GLOBALS["id"]);。这仅仅是全局变量处理的一个问题。您应当总是使用 $GLOBALS,在更新版本的 PHP 4 中您应该强迫自己在大部分情况中使用它。更多信息请参考 global 参考章节.

例子 C-1. 全局变量的移植

<?php
$id
= 1;
function
test()
{
   global
$id;
   unset(
$id);
}
test();
echo(
$id); // 在 PHP 4 中这里会打印出 1
?>



<Cookies从 PHP/FI 2 移植到 PHP 3>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST