问题描述
[PHP]
函数blah($ item){
if(!isset($ baseDir)){
static $ baseDir ='''';
$ baseDir = $ item;
print_r(" baseDir = $ baseDir \ n");
}
$ dirID = opendir($ item);
while(($ fyl = readdir($ dirID))!== false){
if(is_dir(" $ baseDir / $ fyl"))blah($ item);
//如果它是一个文件,请做其他麻烦
}
}
[/ PHP]
我使用PHP 4.3.2并且以下内容发生在blah中( ):
[PHP]
function blah($item) {
if (!isset($baseDir)) {
static $baseDir = '''';
$baseDir = $item;
print_r("baseDir = $baseDir\n");
}
$dirID = opendir($item);
while (($fyl = readdir($dirID)) !== false) {
if (is_dir("$baseDir/$fyl")) blah($item);
// DO OTHER STUFF IF IT IS A FILE
}
}
[/PHP]
I am using PHP 4.3.2 and the following occurs within blah() :
我的印象是静态变量保留其值
整个函数(或方法)递归内存堆栈。然而,它每次都会改变
因为它显然会失去它的设定值。
不用说我很困惑。我对静态是错的;如果是的话,
我还能做些什么来保留这个价值?我不能使用$ _SESSION这个
是命令行PHP而不是API。
Thanx
Phil
I was under the impression that a static variable retains its value
throughout a function (or method) recursive memory stack. However, it
changes everytime because it apparently loses its set value.
Needless to mention I''m confused. Was I wrong about static; if so,
what else do I do to retain this value? I cannot use $_SESSION as this
is command-line PHP instead of API.
Thanx
Phil
推荐答案
这篇关于当“静态”时不是“静态的”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!