php 增加嵌套函数调用限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4293775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:33:34  来源:igfitidea点击:

Increasing nesting function calls limit

phpxdebug

提问by barbushin

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

PHP 中有一个非常糟糕的限制:如果你调用某个调用 a2() 的函数 a1(),它调用 a3...所以什么时候a99()调用a100()你会看到

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

致命错误:达到“100”的最大函数嵌套级别,正在中止!

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

有什么办法可以将 100 次嵌套调用的限制增加到 500 或 10000 次?

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

这对我来说很重要,因为我正在开发一个带有大量回调的基于事件的系统。

回答by netcoder

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

此错误消息专门来自 XDebug 扩展。PHP 本身没有函数嵌套限制。更改php.ini 中的设置

xdebug.max_nesting_level = 200

or in your PHP code:

或在您的 PHP 代码中:

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.

至于你是否真的需要改变它(即:如果有递归函数的替代解决方案),没有代码我无法判断。

回答by Ryan C -Xnuiem- Meinzer

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

您是否安装了 Zend、IonCube 或 xDebug?如果是这样,那可能是您收到此错误的地方。

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.

几年前我遇到了这个问题,最终是 Zend 把这个限制放在那里,而不是 PHP。当然删除它会让你超过 100 次迭代,但你最终会达到内存限制。

回答by Antony

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.

输出错误并查看触发的位置。