phptools icon indicating copy to clipboard operation
phptools copied to clipboard

Dump does not have a recursion limit

Open fidian opened this issue 13 years ago • 4 comments

When dumping this sort of a structure, Dump breaks.

$v = 'Hi';
for ($i = 0; $i < 50; $i ++) {
    $v = array($v);
}
Dump::out($v, 'Deeeeeeeeep');

It's actually worse with nested objects - we can't go as deep due to calls to dumpAnything -> dumpObject -> objectstdClass.

fidian avatar Sep 26 '12 21:09 fidian

Perhaps FirePHP can offer a suggested way to handle this. (see the "encodeObject" method). https://github.com/firephp/firephp-core/blob/master/lib/FirePHPCore/FirePHP.class.php#L1301

Holding objects during processing could have some performance impacts; however, since this is a development tool only, I don't forsee it being a significant concern.

wjaspers avatar Sep 10 '13 06:09 wjaspers

What about not using recursion? You should be able to flatten the structure and while loop until you've navigated the structure. Might run into memory concerns detecting recursion, but that's already a concern I believe.

garadox avatar Sep 10 '13 13:09 garadox

I believe that there are two problems here. First, we use recursion and so we hit PHP's recursion limit. Secondly, there's no way of stopping Dump from reporting the whole object. I might only care about the first couple of levels.

fidian avatar Sep 10 '13 13:09 fidian

Maybe the structure of Dump's call should change? Dump::someDifferentMethod($content, $depth);

The purpose of dump is to peer into the data in a variable. Choosing a reasonable depth IMHO is really in the eye of the caller. Perhaps if someone is blindly calling the method, they're using the tool incorrectly.

For example, lets assume dump's default recursion limit is 2, and the method signature is public function method($something, $depth = 2).

Johnny Developer needs to access a piece of data contained in his variable... Dump::method($user)


(object) Person::__setState(array(
      'siblings' => array(
          'Gina' => (object) Person::__setState(array(
               'siblings' => array(
                   'Johnny' => (object) Person::__setState(array(
                        'siblings' => array(
                            'Gina' => (*** recursion ***)
                        ),
                   ),
               ),
          )),
      ),
 ));

The side effect here, is that you don't get clean output that can be simply cut-and-paste for use. (As is sometimes useful with Dump)

wjaspers avatar Sep 11 '13 01:09 wjaspers