Posted by comp.lang.php on 12/05/05 21:02
[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() :
[Quote]
baseDir = /home/me/stuff
baseDir = /home/me/stuff/.
baseDir = /home/me/stuff/./..
[/Quote]
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
Navigation:
[Reply to this message]
|