4

I'm trying to see what is inside all the objects of the Magento system, but when I try to var_dump the $_links variable (containing all information needed for rendering the links in the header of every page) from inside the top links template, my server responds with a 500 error. Anyone know why?

pancake
  • 1,923
  • 2
  • 21
  • 42

7 Answers7

14

Dumps of Magento objects get a bit messy, even if there isn't recursion there is all the EAV and cache stuff. When you have an array you'll need to dump them individually:

foreach ($_links as $object) {
    var_dump($object->debug());
}
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
  • For anyone that needs to know: I accepted this answer, because it works and is the easiest solution to implement. I take it xDebug would solve the problem as well, but somehow it's already on my system (not sure if it's active in php though). – pancake Jul 29 '11 at 07:53
  • If you're just after an easy solution, you could also directly dump to a file, e.g. `error_log(print_r($_links, true), 3, 'my.log')` or the like. Sometimes I use this myself when in need of dumping extra large Magento objects. – Jürgen Thelen Jul 29 '11 at 17:15
  • Great it works for me vew phtml file, below my code i use – matinict May 14 '19 at 09:00
3

It's likely a memory error. Magento's object can be huge, and the default var_dump implementation in PHP isn't that smart about some of the circular references.

Install xDebug is a must. With xDebug, the var_dump function gets a lot smarter, and the memory limit exhausted errors mostly go away.

Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • How do I install xDebug when I already see a xdebug.so file in /usr/lib/php/extensions/ ? – pancake Jul 28 '11 at 17:31
  • 1
    Xdebug is a must, but only on dev/local envs. Please don't put tools like this on your production server. – Mike G Jul 28 '11 at 18:20
  • apparently I have xdebug installed, it shows up in my phpinfo() output. So printing the whole array just isn't an option. – pancake Jul 29 '11 at 08:09
  • @pancake Make sure you have the PHP.ini settings mentioned here http://xdebug.org/docs/display set. You'll know you're using xDebug's var_dump if you var_dump("test"); in a browser and you can see the unescaped html tags (xDebug escapes it for you). Tweaking xdebug.var_display_max_children, xdebug.var_display_max_data and xdebug.var_display_max_depth should let you safely dump out 95% of the data structures you'll encounter. – Alana Storm Jul 29 '11 at 15:58
2

Magento is a huge memory hog. Most likely, you're running out of available memory.

Instead of var dumping the object itself, dump the objects data using its ->toArray() method. Note: all Mage_ objects inherit this method.

Mike G
  • 758
  • 6
  • 18
  • found the problem, apache error log shows "Allowed memory size of 268435456 bytes exhausted (...)", so printing any object of this kind is not an option? – pancake Jul 28 '11 at 15:36
2

HTTP 500 errors will occur in scenarios like this when PHP spewed an error, and you did not configure your setup to display it to the user.

Look in your error log (something like /var/lib/httpd/log/error_log) to find out what's actually going on.

Possibilities include:

  • Syntax error
  • Headers already sent before output
  • Memory exhaustion from printing huge variable
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

In most of cases it's because $_links variable contains a lot of huge nested objects. Try the xDebug extension for PHP - it allows to tune var_dump output to limit nesting level and amount of displaying data.

vsushkov
  • 2,445
  • 1
  • 19
  • 28
  • `var_dump` doesn't choke on recursion, it just shows `** RECURSION **` in place of a recursive member. – Rudi Visser Jul 28 '11 at 15:12
  • I tried installing xDebug, but in the extension folder I already found a file named xdebug.so. Does xdebug come preinstalled with OS X? I'm using the built-in webserver of Mac OS X Lion. I also added a line "extension=xdebug.so" to my php.ini, but now I get an empty 200 response. – pancake Jul 28 '11 at 15:30
0

$_link variable consist huge number of objects inside, we needs to debug to print the object

print_r($_link->debug());
(or)
var_dump($_link->debug());
Mahendra Jella
  • 5,450
  • 1
  • 33
  • 38
0

I solve my var_dump(array) result in a 500 error in Magento2 issue as below(May be someone help)

//app/code/MyCompany/Shipping/view/adminhtml/templates/order/view/items.phtml

foreach ($_items as $_item):
    echo "<pre>";
    var_dump($_item->debug());
    echo "</pre>";

Sample Output: enter image description here

matinict
  • 2,411
  • 2
  • 26
  • 35