php 如何让 xdebug var_dump 显示完整的对象/数组

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9998490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 08:03:48  来源:igfitidea点击:

How to get xdebug var_dump to show full object/array

phpxdebug

提问by dm03514

I am using xdebug(php_xdebug-2.1.2-5.3-vc9.dll) on WAMP. When I use var_dumpon a large object or variable it does not show the full variable.

我在WAMP上使用xdebug(php_xdebug-2.1.2-5.3-vc9.dll) 。当我在大对象或变量上使用时,它不会显示完整的变量。var_dump

array
'node' => 
  array
    'my_form' => 
      array
        'form' => 
          array
            ...

Without xdebug it shows as should be expected. I looked at the documentation but did not see a solution. Does anyone know how I can fix this so xdebug var_dumpshows the fullobject?

如果没有 xdebug,它会按预期显示。我查看了文档,但没有看到解决方案。有谁知道我如何解决这个问题,以便 xdebugvar_dump显示完整的对象?

回答by Michael Berkowski

These are configurable variables in php.ini:

这些是 php.ini 中的可配置变量:

; with sane limits
xdebug.var_display_max_depth = 10
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = 1024 


; with no limits
; (maximum nesting is 1023)
xdebug.var_display_max_depth = -1 
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1 

Of course, these may also be set at runtime via ini_set(), useful if you don't want to modify php.ini and restart your web server but need to quickly inspect something more deeply.

当然,这些也可以在运行时通过 设置ini_set(),如果您不想修改 php.ini 并重新启动 Web 服务器,但需要快速更深入地检查某些内容,这将很有用。

ini_set('xdebug.var_display_max_depth', '10');
ini_set('xdebug.var_display_max_children', '256');
ini_set('xdebug.var_display_max_data', '1024');

Xdebug settings are explained in the official documentation.

Xdebug 设置在官方文档中有解释

回答by Chris Schmitz

I know this is a super old post, but I figured this may still be helpful.

我知道这是一个超级旧的帖子,但我认为这可能仍然有帮助。

If you're comfortable with reading json format you could replace your var_dump with:

如果您对阅读 json 格式感到满意,则可以将 var_dump 替换为:

return json_encode($myvar);

I've been using this to help troubleshoot a service I've been building that has some deeply nested arrays. This will return every level of your array without truncating anything or requiring you to change your php.ini file.

我一直在使用它来帮助解决我一直在构建的具有一些深层嵌套数组的服务的故障。这将返回数组的每一层,而不会截断任何内容或要求您更改 php.ini 文件。

Also, because the json_encoded data is a string it means you can write it to the error log easily

此外,由于 json_encoded 数据是一个字符串,这意味着您可以轻松地将其写入错误日志

error_log(json_encode($myvar));

It probably isn't the best choice for every situation, but it's a choice!

它可能不是每种情况的最佳选择,但它是一种选择!

回答by raveren

Or you can use an alternative:

或者您可以使用替代方法:

https://github.com/kint-php/kint

https://github.com/kint-php/kint

It works with zero set up and has much more features than Xdebug's var_dump anyway. To bypass the nested limit on the fly with Kint, just use

它在零设置下工作,并且具有比 Xdebug 的 var_dump 多得多的功能。要使用 Kint 即时绕过嵌套限制,只需使用

 +d( $variable ); // append `+` to the dump call

回答by 0x58

I know this is late but it might be of some use:

我知道这已经晚了,但它可能会有用:

echo "<pre>";
print_r($array);
echo "</pre>";

回答by Captain Insaneo

Checkout Xdebbug's var_dump settings, particularly the values of these settings:

检查Xdebbug 的 var_dump 设置,特别是这些设置的值:

xdebug.var_display_max_children
xdebug.var_display_max_data
xdebug.var_display_max_depth

回答by Nino ?kopac

I'd like to recommend var_export($array)- it doesn't show types, but it generates syntax you can use in your code :)

我想推荐var_export($array)- 它不显示类型,但它会生成您可以在代码中使用的语法:)