How to get current recursion level in a PHP function

前端 未结 5 1890
灰色年华
灰色年华 2021-01-18 05:20

How to get current recursion level in a PHP function ? I mean, is there any \"magical\" (or eventually normal) function like this :

function doSomething($thi         


        
5条回答
  •  悲哀的现实
    2021-01-18 05:31

    You need to count it yourself, the only alternative would be something like XDebug which profiles your complete software. But this is highly inefficient.

     $v) {
    
            }
        }
        else {
            echo $counter;
            --$counter;
    
            // If we're returning (only PHP 5.5+)
            try {
                return $counter;
            }
            finally {
                --$counter;
            }
        }
    }
    
    ?>
    

    This allows you to count without a second public parameter.

提交回复
热议问题