电影下载
http://210.76.223.28/movie/ 我的机器,测试速度如何!
- 娱乐乐园,
作者 Hicazm 发布于 2003-09-01 分类:php基础编程
在php手册中有个unset()例子说:
[PHP] 如果在函数中 unset() 一个静态变量,则 unset() 将销毁此变量及其所有的引用。
<?php
function foo() {
static $a;
$a++;
echo "$a
";
unset($a);
}
foo();
foo();
foo();
?>
上边的例子将输出:
1
2
3
[/PHP]
为什么不是输出:
1
1
1
呢?
逛论坛交流:unset()问题
是不是他的问题?static $a;
他保留了原有的值
不过 unset($a); 摧毁 $a 了呀
这个问题有点邪门!
没看过静态变量的介绍,原因就搞不懂了:(
手册的解释错误,或者是PHP的BUG
admin at /networkessence dot net
24-May-2002 08:40
If a static variable is unset() inside of a function, unset() destroyes the variable and all its references.
This statement is clearly false given the following example:
function foo() {
static $a;
$a++;
echo "$a
";
unset($a);
}
foo();
foo();
foo();
The above example would output:
1
2
3
If $a was being destroyed, then it would not increment (bug I guess). BUT
unset does work properly outside of functions
Example:
static $a;
$a++;
echo $a;
unset($a);
$a++;
echo $a;
unset($a);
would output:
1
1
which is correct. I would assume this is a bug considering the output of the first example contradicts the manual.
7 条回复
回复