请看下面的例子:
// 例子1
function test_global() {
global $var1, $var2;
$var2 =& $var1;
}
function test_globals() {
$GLOBALS['var3'] =& $GLOBALS['var1'];
}
$var1 = 5;
$var2 = $var3 = 0;
test_global();
print $var2 ."\n";
test_globals();
print $var3 ."\n";
function test_global() {
global $var1, $var2;
$var2 =& $var1;
}
function test_globals() {
$GLOBALS['var3'] =& $GLOBALS['var1'];
}
$var1 = 5;
$var2 = $var3 = 0;
test_global();
print $var2 ."\n";
test_globals();
print $var3 ."\n";
结果呢,是:
0
5
5
Copy on write,你懂的,呵呵,记录之。