是什么会导致print_r和/或var_dump调试变量失败? [英] What would cause a print_r and/or a var_dump to fail debugging a variable?
问题描述
我正在尝试在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的
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>,
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屋!