PHP致命错误:达到了'100'的最大函数嵌套级别,正在中止! 在Laravel

I had this error twice and spent almost 30 minutes to debug it each time. I Hope it will help somebody because all I've found on the internet is solution for turning off xDebug.

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

This happened to me because I have accidentally injected two classes into each other.

class Foo(Bar $bar){}

class Bar(Foo $foo){}


$bar = new Bar(new Foo(new bar(new Foo(...))));

The reason why didn't saw that is because of Laravel IOC. So synax for instantiating a class would be something like:

$bar = new Bar(Foo $foo);

Here the issue in my case.

I have a service class which is librarie in codeigniter. Having a a function inside like this.

class PaymentService {

    private $CI;

    public function __construct() {

        $this->CI =& get_instance();

    }

    public function procss(){
        // lots of Ci referencing here ...
    }

my controller as followed:

$this->load->library('PaymentService');
$this->process_(); // see I got his wrong instead it should be like below

$this->Payment_service->process(); //the library class name

Then I was keeping getting the exceed error message. But I do disable XDebug but non helped. Any way please check you class name or your code for proper function calling.

Issue is caused by default xdebug.max_nesting_level which is 100.

By adding the line below to bootstrap/autoload.php in Laravel 5.1

ini_set('xdebug.max_nesting_level', 120);

.........

define('LARAVEL_START', microtime(true));

This answered helped me.

https://stackoverflow.com/a/30839127/3524046