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.
-
13100 seems a little excessive, even for an event framework.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2010年11月27日 20:47:05 +00:00Commented Nov 27, 2010 at 20:47
-
7@Ignacio: it's quite simple, even if the focus is on an event framework, to have a recursive function that needs a much higher nesting level. Tens of thousands (or even millions) is not uncommon in such scenario's.Abel– Abel2011年12月28日 12:50:08 +00:00Commented Dec 28, 2011 at 12:50
-
stackoverflow.com/a/36440027/2652524 I solve mine using this answerGujarat Santana– Gujarat Santana2016年04月06日 01:47:45 +00:00Commented Apr 6, 2016 at 1:47
-
@IgnacioVazquez-Abrams If you're doing functional programming instead of object-oriented or procedural, 100 easily is a drop in the bucket. And considering many PHDs in the field recommend using functional over OOP or proc, really, you should always be prepared to have lots of recursive functions.lilHar– lilHar2021年04月14日 21:40:20 +00:00Commented Apr 14, 2021 at 21:40
3 Answers 3
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.
-
I had the same problem. My max_nesting_level was set to 100 but in my case, in some cases, it's possible to have 1000 recursive calls. So, I set to 10000 to avoid this xdebug error. In all cases, it always better than let PHP with no limit.SkaJess– SkaJess2014年10月28日 13:39:37 +00:00Commented Oct 28, 2014 at 13:39
-
9If you don't have this
xdebug.max_nesting_level = 100
option in your php.ini just paste that in.M. Reza Nasirloo– M. Reza Nasirloo2015年03月16日 10:24:27 +00:00Commented Mar 16, 2015 at 10:24 -
@Pedram The correct way to copy that in a php ini file is in /etc/php5/apache2/conf.d/20-xdebug.ini, not in the normal php.ini. Just a good practiceEnrique Quero– Enrique Quero2016年02月17日 16:45:28 +00:00Commented Feb 17, 2016 at 16:45
-
3@EnriqueQuero Depends on the system and OS.netcoder– netcoder2016年02月17日 17:04:25 +00:00Commented Feb 17, 2016 at 17:04
-
It works! No matter if you use XDebug or not, neither if you comment out line in php.ini. I explicitly used: ini_set('xdebug.max_nesting_level', -1);user2928048– user29280482016年05月09日 14:19:58 +00:00Commented May 9, 2016 at 14:19
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.
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.