为什么 var_dump(array) 会在 Magento 中导致 500 错误?

发布于 2024-11-27 04:42:47 字数 118 浏览 6 评论 0原文

我试图查看 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

羁客 2024-12-04 04:42:47

Magento 对象的转储有点混乱,即使没有递归,也有所有 EAV 和缓存内容。当你有一个数组时,你需要单独转储它们:

foreach ($_links as $object) {
    var_dump($object->debug());
}

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());
}
我的奇迹 2024-12-04 04:42:47

这很可能是内存错误。 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.

没︽人懂的悲伤 2024-12-04 04:42:47

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.

永言不败 2024-12-04 04:42:47

当 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:

  • Syntax error
  • Headers already sent before output
  • Memory exhaustion from printing huge variable
还不是爱你 2024-12-04 04:42:47

在大多数情况下,这是因为 $_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.

过潦 2024-12-04 04:42:47

$_link 变量内部包含大量对象,我们需要调试才能打印对象

print_r($_link->debug());
(or)
var_dump($_link->debug());

$_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());
终遇你 2024-12-04 04:42:47

我解决了我的 var_dump(array) 结果在 Magento2 问题中的 500 错误,如下(可能有人帮忙)

//app/code/

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

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

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

Sample Output:
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文