Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 228

CodeIgniter model method using recursion unexpectedly returns null [duplicate]

$
0
0

I have this method called treetrunk() that runs up a parent child relationship and is supposed to return an array if ids as a "branchPath" - the method seems to be working just fine as a var_dump() call in my terminating condition shows the proper array. However if I try to call the method the returned array is "NULL" - I really don't get it.

Model method:

function treeTrunk($id){    if ($id == '0') {        var_dump($this->branchPath); //this shows perfect array         return $this->branchPath; //this returns null    } else {        $q = $this->getWhere(array('id' => $id), null, null);        array_push($this->branchPath, $q[0]['pageParent']);        $this->treeTrunk($q[0]['pageParent']);    }       }

Calling via controller:

$d = $this->pages_mdl->treeTrunk('150');var_dump($d); // <- this == NULL

var_dump() from within the method outputs:

array(3) {  [0]=> string(3) "148"  [1]=> string(3) "146"  [2]=> string(1) "0"}

Viewing all articles
Browse latest Browse all 228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>