简体   繁体   English

当我使用var_dump变量调试php时,总是在开始时输出文件路径吗?

[英]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

    • Meaning: Ancester: Two directory elements and filename 含义:Ancester:两个目录元素和文件名
    • Example Output: mail/transport/mta.php 示例输出:mail / transport / mta.php
  • Specifier : %f 说明符:%f

    • Meaning: Full path 含义:完整路径
    • Example: /var/www/vendor/mail/transport/mta.php 示例:/var/www/vendor/mail/transport/mta.php
    • (is default setting) (默认设置)
  • Specifier: %n 说明符:%n

    • Meaning: Name - Only the file name 含义:名称-仅文件名
    • Example: mta.php 示例:mta.php
  • Specifier: %p 说明符:%p

    • Meaning Parent - One directory element and the filename 含义父级-一个目录元素和文件名
    • Example: transport/mta.php 示例:transport / mta.php
  • Specifier: %s 说明符:%s

    • Meaning: Directory separator 含义:目录分隔符
    • Example: \\ on Linux, OSX and other Unix-like systems, / on Windows 示例:\\在Linux,OSX和其他类似Unix的系统上,/在Windows上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM