I am using Ubuntu with PHP 7.
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:
<?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
It seems You have Xdebug enabled. You can disable it from your php.ini file Find for Xdebug in php.ini and replace it with
The output you're seeing is from the Xdebug extension. (Without the extension,
var_dump
outputs plain, unformatted text.)From Xdebug 2.3, the setting
xdebug.overload_var_dump
has a new default value of2
which adds the filename and line number to the output from any call tovar_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: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.
Ref: https://xdebug.org/docs/all_settings#filename_format
Specifier : %a
Specifier : %f
Specifier: %n
Specifier: %p
Specifier: %s