为什么 var_dump(array) 会在 Magento 中导致 500 错误?
我试图查看 Magento 系统的所有对象内部有什么,但是当我尝试从顶部链接模板内部 var_dump $_links 变量(包含渲染每个页面标题中的链接所需的所有信息)时,我的服务器响应 500 错误。有人知道为什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Magento 对象的转储有点混乱,即使没有递归,也有所有 EAV 和缓存内容。当你有一个数组时,你需要单独转储它们:
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:
这很可能是内存错误。 Magento 的对象可能很大,而 PHP 中默认的 var_dump 实现对于某些循环引用并不那么聪明。
必须安装xDebug。借助 xDebug,
var_dump
函数变得更加智能,并且内存限制耗尽错误大部分都会消失。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.Magento 是一个巨大的内存消耗者。最有可能的是,您的可用内存不足。
不要使用 var 转储对象本身,而是使用其
->toArray()
方法转储对象数据。注意:所有Mage_对象都继承该方法。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.当 PHP 发出错误并且您没有配置设置以将其显示给用户时,在这种情况下就会出现 HTTP 500 错误。
查看错误日志(例如
/var/lib/httpd/log/error_log
)以了解实际发生的情况。可能的情况包括:
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:
在大多数情况下,这是因为 $_links 变量包含很多巨大的嵌套对象。尝试 PHP 的 xDebug 扩展 - 它允许调整 var_dump 输出以限制嵌套级别和显示数据量。
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.
$_link
变量内部包含大量对象,我们需要调试才能打印对象$_link
variable consist huge number of objects inside, we needs to debug to print the object我解决了我的 var_dump(array) 结果在 Magento2 问题中的 500 错误,如下(可能有人帮忙)
//app/code/
MyCompany /Shipping/view/adminhtml/templates/order/view/items.phtml 示例输出:

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
Sample Output:
