New in Xdebug 2.2: Colours on the command line

Xdebug 2.2 版本引入了新的功能,改进了 var_dump 的显示限制,并支持在命令行环境中使用这些限制。此外,还新增了颜色编码功能,即使在 Windows 控制台中也能使用 ANSI 逃逸码来显示颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

xdebug安装后,var_dump()不起作用

解决办法:打开 html_error=1

因为通过网页变色,都是通过html css控制的,打开这个属性,var_dump才会起作用


This is the first article in a series about new features in Xdebug 2.2. Besides support for PHP 5.4, there are a few that might be of interest.

Xdebug has overloaded var_dump() with xdebug_var_dump() for a long time and the overloaded function could be configured with a few configuration settings. There is xdebug.var_display_max_data to configure how much of a string should be shown; xdebug.var_display_max_children to configure how many children in an array should be shown and xdebug.var_display_max_depth to configure how many levels "deep" the var_dump() should go on for. This functionality was available for when PHP had its html_errors setting on as is usually the case in a web environment1.

Xdebug 2.2 adds this same functionality to the non-HTML environment: the command line. Now the overloaded var_dump() and native xdebug_var_dump() functions also accept the three aforementioned settings:

derick@whisky:~$ php \
        -dxdebug.var_display_max_data=8 \
        -dxdebug.var_display_max_children=4 \
        -r 'var_dump( "a longer string", array( 1, 2, 3, 4, 5, 6, 7 ) );'

outputs:

string(15) "a longer"...
array(7) {
  [0] =>
  int(1)
  [1] =>
  int(2)
  [2] =>
  int(3)
  [3] =>
  int(4)

  (more elements)...
}

Now, to be fair. This is all a side effect; and merely an add-on to a patch byMichael Maclean. He wrote a patch that adds colours to the output on the command line by using ANSI escape codes. This patch also made the overloaded var_dump()listen to the limiting settings for variable display. After his patch, the following was the behaviour on the command line as long as stdout is a tty andxdebug.cli_color is set to 1.

cli-color-linux.png

I have extended this so that the settings regarding data display also work without xdebug.cli_color set to 1. Further more, in Xdebug 2.2.0RC1, settingxdebug.cli_color to 2 forces the colours from being shown, even if stdout is not a tty.

Initially, the colour coding of errors and var_dump() output, would only work on a Unix system where ANSI escape codes are commonly supported. After the release of Xdebug 2.2.0RC1, Chris Jones submitted a bug report suggesting that this functionality could also be available on the Windows console. I wasn't aware that Windows could do this anymore since they dropped ANSI.SYS but apparently there is a tool, ANSICON, that reimplements this. From the next release, Xdebug 2.2.0RC2, Xdebug will now also check whether the ANSICON environment variable is set, just like Xdebug would check whether stdout is a tty on a Unix platform. As a result, the equivalent console output as shown before looks like the following on Windows (providing ANSICON is installed):

cli-color-windows.png

Now the only thing left is adding complete documentation for this feature ;-)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

anssummer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值