Recursive function not returning a value in PHP

choa

New Member
I've got a recursive function defined as follows\[code\]private function _buildPathwayRecurse(&$category, &$reversePathway = array()) { $category->uri = FlexicontentHelperRoute::getCategoryRoute($category->id); $reversePathway[] = $category; if ($category->parent_id != 0) { $category = $this->_getCatForPathway($category->parent_id); $this->_buildPathwayRecurse($category, $reversePathway); } else { return $reversePathway; }}\[/code\]and I'm calling it like so\[code\]$reversePathway = $this->_buildPathwayRecurse($category);\[/code\]However $reversePathway ends up being null. Any idea why that is? I've stepped through my code using XDebug and as far as I can tell everything works as it should. When I get to the line\[code\]return $reversePathway\[/code\]$reversePathway looks perfect. It's persisting through the function calls and gaining a new item each time. right before executing the return line it's got an array of a few items just like it should be, but by the time I get out to\[code\]$reversePathway = $this->_buildPathwayRecurse($category);\[/code\]it seems to just dissapear!
 
Back
Top