是什么会导致print_r和/或var_dump调试变量失败? [英] What would cause a print_r and/or a var_dump to fail debugging a variable?

查看:55
本文介绍了是什么会导致print_r和/或var_dump调试变量失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Magento中调试PayPal审核过程.每次我试图转储下面的变量,我得到一个白色的页面:

I'm attempting to debug the PayPal review process in Magento. Every time I try to dump the following variable I get a white page:

//the variable declaration:
$shippingAddress = $this->getShippingAddress();

//the dump that breaks the page:
 <?php echo '<pre>';print_r($shippingAddress);echo '</pre>'; ?>

我也试图与正被用于除if语句以外的内容页面上的变量.

I also tried with a variable on the page that was being used for something other than if statements.

//this variable displays results
<?php echo '<pre>';print_r($billingBlock->setShowAsShippingCheckbox(true)->toHtml());echo '</pre>'; ?>

//however, this one does not:
<?php echo '<pre>';print_r($billingBlock);echo '</pre>'; ?>

我只是想知道什么会导致var_dump中断页面?如何看什么是对象,如果我不能放弃它?

I was just wondering what might cause my var_dump to break the page? How do I see what is in the object if I can't dump it?

推荐答案

首先,PHP从不 只是白页".当您出现空白屏幕时,这意味着PHP的执行由于某种原因而停止了.但是,除非将服务器配置为不记录错误,否则PHP错误日志或Magento异常日志应该为您提供一个错误.

First, PHP never "just white pages". When you get a blank screen, that means PHP's execution has halted fro some reason. However, unless your server has been configured to not log errors, the PHP error log or the Magento exception log should have an error for you.

就您的特定问题而言,Magento的许多对象都包含对大量信息的引用-有时引用是循环的. PHP的功能会盲目追随这些循环引用,并尝试打印出来的一切.使用更多的存储器来PHP这最终导致比由 INI设定,并执行暂停允许的.

As far as your specific problem goes, many of Magento's objects contain reference to a large amount of information — and sometimes the references are circular. PHP's var_dump and print_r functions will blindly follow these circular references and attempt to print everything out. This eventually leads to PHP using more memory than is allowed by the memory_limit ini setting, and execution halts.

大多数PHP专业人士使用的XDebug 扩展程序来解决此. xDebug扩展具有经过修改的var_dump,它将限制转储的信息量,从而避免了上述内存限制问题.在<4>,和<6> INI设置是你要调整,如果Xdebug的仍然无法与内存的限制问题帮助的人. (一些PHP分布具有这些组过高最初)

Most PHP professionals use the xDebug extension to work around this. The xDebug extension has a modified var_dump that will limit the amount of information dumped, which prevents the above memory limit problems. The xdebug.var_display_max_children, xdebug.var_display_max_data, and xdebug.var_display_max_depth ini settings are the ones you'll want to tweak if xDebug's still not helping with the memory limit problem. (some PHP distributions have these set too high initially)

如果这是不可能的,则对您的var_dump谨慎一点仍然可以提供帮助.

If that's not a possibility, a little caution with your var_dump's can still help.

使用此找出变量类型

var_dump(get_class($thing));

如果这是一个Magento的对象,使用此以查看其数据键

If it's a Magento object, use this to see its data keys

var_dump(array_keys($thing->getData()));

然后使用

var_dump($thing->getData('key_name'));
var_dump($thing->getKeyName()));

这篇关于是什么会导致print_r和/或var_dump调试变量失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆