#1 September 2, 2014 4:46pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Recursive Functions in Custom Classes

Is there a reason that the following recursive function generates an error when being implemented in my BigTreeCustom class? Other functions in this class work fine and it seems like this function works until the recursive call. I also tried writing another recursive function and received the same error. Is there something BigTree does to prevent this?

function recursive($number)	{
    echo $number;
    $number = $number - 1;
   if($number > 0):
         recursive($number);
    else:
         echo "Finished";
    endif;
}

The error returned is Fatal error: Call to undefined function recursive() in \custom\admin\class_extensions\BigTree.php on line 118 (which references the recursive call inside the if statement).

Thanks

Offline

#2 September 3, 2014 12:20pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Recursive Functions in Custom Classes

Since "recursive" is defined in a class you need to call it with $this->recursive as it's a method of the class and not a global function.

Offline

#3 September 3, 2014 2:15pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Re: Recursive Functions in Custom Classes

That makes sense.

Thanks for your help.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.