Recursive Function returning emptry string
I’m completely flummoxed by this behavior. In trying to debug, I have the function echo the function name and its arguments. I also have the function return a value upon termination and I echo this as well. One might think that there is an error in the function, but I even echo the string I’m going to return right before the return statement and I get the desired value, but somehow this value disappears when the function returns.
Since this involves some SQL queries, I’m omitting the actual code but here is the gist of the function and its output in psuedocode.
<?php
function Recur($name, $id)
{ //actual code
echo 'Recur('.$name.','.$id.')<br>';
if($id == 0)
return $name;
//end comment
//pseudo code
else{
//do something
Recur($tmpname, $id-1);
}
//end comment
}
$result = Recur($name, $id);
echo $result;
?>
Here is actual output:
|
Recur(Updated Account, 0) Recur(Test Account3, 0) |
When I remove the echo $result line and insert echo $name before return $name, I get the same output as above, but the blank line is replaced with Updated Account:TestAccount1 as expected.
Has anyone seen this behavior before?
I might just give up and write a while loop. Oh PHP you disappoint me!
View Complete Thread with Replies
No Reply.
Find related on my parent xResources.