views:

580

answers:

5

Hi!

I have a very strange problem, when I try to var_dump (or print_r) a PHPDoctrine Object, my Apache responses with an empty blank page (200 OK header). I can var_dump a normal php var like:

$dummy = array("a" => 1, "b" =>2);

And it works fine. But I can't with any object from any Doctrine class, (like a result from $connection->query(), or an instance of a class from my object model with Doctrine).

Anybody knows why this happens?

Thanks and sorry for my bad english =) !

+4  A: 

I've had that sometimes when trying to print_r() a self-referencing object - it gets into a loop and runs out of memory. Possibly that's what's happening to you.

Try increasing the memory limit (ini_set('memory_limit', '256M');) and see if that fixes it.

Edit: I don't think there's an actual fix for this - it's PHP's internal var_dump / print_r that don't limit depth on recursion (or don't do it properly, at least). If you install the XDebug extension, this can replace the built-in var_dump with a version that handles recursion much better.

Greg
A: 

@RoBorg

With memory limit set to 256M, my localhost kepts loading a few minutes and after that returns a empty page (200 OK header). Then, I think the problem could be memory as you suggest, but I can't understand why Apache is not returning a memory error. I have only 512 MB so I can't try with much more...

Thanks btw.

PD: My php.ini is set to show all errors.

A: 

Thanks! I'll try XDebug =) (Zend Debugger in Zend Studio is too heavy for me!)

A: 

I never had problems since print_r recognizes recursion since PHP 4.0.4 and var_dump has a recoursion limit.

You never should use print_r/var_dump/var_export in a ob_start callback, since they use ob_* themselves. So where do you use this functions?

Jochen
A: 

Use the toArray method of the Doctrine_Record class

var_dump($doctrine_record->toArray());

will only display the DB fields and avoid dumping the complete Doctrine internals (which contains self reference/recursion btw)

Julien