Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Is there any reason to use with(clone $model)?

I was working on a code that loads way too much data (75+ MB in resources), and I noticed they used something like:

$model = with(clone $model)->... // (Yes, same model instance lol)

I've never seen anything like that but I know it's a new developer who worked on it. But maybe there is a reason he did that with guidance from other experienced developers that were there previously? I suspect this is part of the massive amount of resources that the page loads

0 likes
4 replies
Sinnbeck's avatar

By itself it does not seem to make sense, but perhaps you can show the surrounding code to better provide clarity? I mean maybe they needed to change a clone but keep the original for something else

1 like
Ligonsker's avatar

@Sinnbeck Tomorrow if I still have access to that code and I will need to work on it I will provide the example here (I'm just not near the code right now and can't get it)

Ligonsker's avatar

@Sinnbeck update: There is some weird syntax in the code:

$eloquent_query = SomeModel::select....
$eloquent_query = with(clone $eloquent_query)...

Like, they used the with helper wrong? I really think they just did a mistake there. Everything there looks odd. Sorry once again I don't have more pieces of code I tried to remember it but that's all I remembered

Please or to participate in this conversation.