Increasing nesting function calls limit

PhpXdebug

Php Problem Overview


There is one very bad limit in PHP: if you call some function a1() that calls a2(), that calls a3... so when a99() will call a100() you will see

> Fatal error: Maximum function nesting level of '100' reached, aborting!

Is there any way to increase the limit of 100 nesting calls to 500 or 10000?

This is critical for me because I'm developing an event-based system with a lot of callbacks.

Php Solutions


Solution 1 - Php

This error message comes specifically from the XDebug extension. PHP itself does not have a function nesting limit. Change the setting in your php.ini:

xdebug.max_nesting_level = 200

or in your PHP code:

ini_set('xdebug.max_nesting_level', 200);

As for if you really need to change it (i.e.: if there's a alternative solution to a recursive function), I can't tell without the code.

Solution 2 - Php

Do you have Zend, IonCube, or xDebug installed? If so, that is probably where you are getting this error from.

I ran into this a few years ago, and it ended up being Zend putting that limit there, not PHP. Of course removing it will let you go past the 100 iterations, but you will eventually hit the memory limits.

Solution 3 - Php

Personally I would suggest this is an error as opposed to a setting that needs adjusting. In my code it was because I had a class that had the same name as a library within one of my controllers and it seemed to trip it up.

Output errors and see where this is being triggered.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbarbushinView Question on Stackoverflow
Solution 1 - PhpnetcoderView Answer on Stackoverflow
Solution 2 - PhpRyan C -Xnuiem- MeinzerView Answer on Stackoverflow
Solution 3 - PhpAntonyView Answer on Stackoverflow