Slim 3 - Catching Echo and var_dump

As the title says. I want to know if its possible to catch echo and var_dump data into the Response object as I use JSON to my response model I wanted to put everything that is written by echo or var_dump into my Data Structure.

My controller class already format my response to this structure:

{
“payload”
“message”
}

but whenever I use var_dump or echo it just concatenate to my previous response. ( Correctly behaviour, I know )

Example:

$a = 2;

If I use var_dump($a) it would concatenate to this: ( Same goes to Echo )

{

“payload”
“message”

}int(2)

I would like to catch/handle this Data so I could do something like this:

{

“payload”
“message”
“debug”:{
“1”:“int(2)”
}

}

Same thing with echo, that roughly concat data to the response object. Any ideas how to do that ?

If possible an explanation to how Slim handles the output from Echo and Var_Dump.

Tricky. My advice is to use monolog and write to the error_log