CamKem's avatar
Level 10

Preventing Recursion in the ServiceProvider Pattern

Im building a framework for... fun? 😅

Can someone more knowledgable that me, help me understand how Laravel avoids recursion in the ServiceProviders when they are registered, seeing as they hold a reference to the Application & they are registered in the IoC container?

Container Dump

0 likes
4 replies
Snapey's avatar

the recursion is only in var_dump or print_r I think

CamKem's avatar
Level 10

@Snapey Oh, damn. Really?

I thought it was causing a memory leak. Ive been digging through the Container, Application & ServiceProvider class object in Laravel for the past few hours to see how they handle this & I can't find where they deal with the recursion. Makes sense if it's just when a var_dump happens.

I was going into all sorts of solutions, like using a Proxy to break the dependancy, but maybe your right.

Is there anywhere that I can read about how the recursion is created by dumping?

CamKem's avatar
Level 10

@Snapey thanks mate, I’ll have a dig into how Symfony have designed dump().

Please or to participate in this conversation.