[英]When I debug php with var_dump variable it always outputs file path at the beginning?
I am using Ubuntu with PHP 7. 我在PHP 7中使用Ubuntu。
PHP 7.0.5-3+donate.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
When I debug a PHP script by using var_dump
to show some variable: 当我使用
var_dump
显示一些变量来调试PHP脚本时:
<?php
var_dump('tmp string');
var_dump(true);
The below is its output: 以下是其输出:
/var/www/example.com/test.php:3:string 'tmp string' (length=10)
/var/www/example.com/test.php:4:boolean true
Why does it always output with the file path before? 为什么总是与以前的文件路径一起输出?
I want it to output like below: 我希望它输出如下:
string 'tmp string' (length=10)
boolean true
The output you're seeing is from the Xdebug extension. 您看到的输出来自Xdebug扩展。 (Without the extension,
var_dump
outputs plain, unformatted text.) (不带扩展名的
var_dump
输出纯文本,未格式化的文本。)
From Xdebug 2.3, the setting xdebug.overload_var_dump
has a new default value of 2
which adds the filename and line number to the output from any call to var_dump
. 从Xdebug 2.3开始,设置
xdebug.overload_var_dump
具有新的默认值2
,该默认值会将文件名和行号添加到对var_dump
任何调用的输出中。 See the docs for more info . 有关更多信息,请参阅文档 。 I agree it's not that useful, especially for simple output like short strings/numbers.
我同意这没什么用,尤其是对于简单的输出(例如短字符串/数字)。
To remove the filename you can set the option to the old value of 1
in your php.ini file: 要删除文件名,可以在php.ini文件中将选项设置为旧值
1
:
[xdebug]
xdebug.overload_var_dump = 1
I ended up here from a search on the topic, but I continued to look for other alternatives and just wanted to add what I found for others. 我从关于该主题的搜索中获得了最终结果,但是我继续寻找其他替代方案,只是想补充一下我为其他人找到的内容。
As of version, Xdebug >= 2.6, there are a few options to modify the display of the file name shown in a var_dump. 从Xdebug> = 2.6版本开始,有一些选项可以修改var_dump中显示的文件名的显示。
// real output example of the %n specifier
courses_list.php:14:string 'tools' (length=5)
Ref: https://xdebug.org/docs/all_settings#filename_format 参考: https : //xdebug.org/docs/all_settings#filename_format
xdebug.filename_format = "[Specifier]"
Type: string, Default value: ...%s%n, Introduced in Xdebug >= 2.6
类型:字符串,默认值:...%s%n,在Xdebug> = 2.6中引入
This setting determines the format with which Xdebug renders filenames in HTML stack traces (default: ...%s%n) and location information through the overloaded xdebug_var_dump() (default: %f).
此设置确定Xdebug通过重载的xdebug_var_dump()(默认值:%f)呈现HTML堆栈跟踪中的文件名的格式(默认值:...%s%n)和位置信息。
Specifier : %a 说明符:%a
Specifier : %f 说明符:%f
Specifier: %n 说明符:%n
Specifier: %p 说明符:%p
Specifier: %s 说明符:%s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.