in reply to Improper use of global variable? (was: Global variables)

Look at your traversal routine. Does it use a variable that was defined outside itself? No. The referred array was defined elsewhere, but that is besides the point (and exactly the raison d'etre for references). Inside the function, you use a variable that holds a reference; this reference came from the function's parameters. No global here.

An approach you might take to make this slightly cleaner would be to declare the actual tree traversal routine as private, and have a public function that declares an array, passes a reference to it and its parameters to the private function, and then returns the results from that array. But it is a question of circumstances and taste whether this is actually any real improvement.

Update: I have to retract some of my statements I guess. Abigail made excellent points about exceptions and reentrance while I was writing this. ++

Makeshifts last the longest.