| Posted by Wayne on 12/05/05 21:17 
On 5 Dec 2005 11:02:31 -0800, "comp.lang.php"<phillip.s.powell@gmail.com> wrote:
 
 >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.
 
 Try it this way:
 
 [PHP]
 function blah($item) {
 static $baseDir = '';
 if (!$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]
  Navigation: [Reply to this message] |