Search code examples
phpvar-dump

Why does var_dump display the file path?


I'm having some problems with var_dump.

This is my code:

$rezultat = 5 < 2;
$rezultat1 = 5 > 2;
var_dump($rezultat);
echo $rezultat1;

And this outputs:

C:\wamp\www\djole-php\test.php:5:boolean false 1

As you can see, var_dump displays the whole path before the result instead of just "boolean false".

Can I make it just show the result without the path?


Solution

  • This is because of xdebug overloading var_dump. If you edit your php.ini and add

    xdebug.overload_var_dump=1
    

    You will no longer get the filename and line number with var_dump. The default setting is 2, which includes the filename and line number with the variable info. A setting of 0 will disable the xdebug override altogether.

    As far as how to update php.ini, there are a lot of xdebug settings that probably aren't defined there, and xdebug will just use their default values. So if it's not there, you can add it and it will override the default. If it is there, just change its value.

    Where you put it doesn't matter too much. If you see any other xdebug settings, you can put it with them. If not, at the end should be fine.


    If you just want to see the value of the variable without any other information, consider using var_export instead of var_dump.