How to get current recursion level in a PHP function
If you are just looking to avoid hitting PHP's 100 level recursion limit then
count(debug_backtrace());
should be sufficient. Otherwise you've no choice to pass a depth argument, though the precrement operator makes it somewhat cleaner as seen in the example below.
function recursable ( $depth = 0 ) {
if ($depth > 3) {
debug_print_backtrace();
return true;
} else {
return recursable( ++$depth );
}
}