Re: Recursion... Sort of...
| From: | David Otton | Date: | Fri, 09 May 2008 00:28:08 +0000 |
| Subject: | Re: Recursion... Sort of... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274045@lists.php.net to get a copy of this message | ||
2008/5/8 Matt Neimeyer <matt@neimeyer.org>:
> Is there a way to tell if a function has been called that has resulted
> in a call to the same function?
debug_backtrace()
Can't comment on performance, though. Its an inelegant solution.
> We have an in-house CRM app that has a function that draws a tabbed
> panel on a screen... BUT if there are sub-sub-tabbed panels we want to
> invert the tab colors and panel colors...
>
> So...
>
> DrawSubTab($Set) - Black on White
> Content
> DrawSubTab($Set) - White on Black
> Content
> DrawSubTab($Set) - Black on White
> Content
> DrawSubTab($Set) - Black on White
> Content
> Etc...
Nested? You may be able to do this in pure CSS, without keeping a
depth counter at all.
> I suppose I could rewrite EVERY call to the function with a recursion
> count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE
> commit... whereas if the function can determine itself... All that
It's an easy change.
function DrawSubTable($Set, $DepthCount = 0)
{
[..]
DrawSubTable($Set, $DepthCount + 1);
[..]
}
By providing a default value, all the calls to DrawSubTable() can
remain unchanged. You just have to modify its own calls to itself.