phpvar-dump

Why does var_dump show filename and line number?


Just recently var_dump() in PHP (currently using 5.6.23) started to print out the filename as well as the line number before actually dumping my variable. I'm not aware of any major changes on the server, so I was wondering why this happens, also there's nothing to be found on the web or in the PHP-documentation (var_dump())

The strange behaviour also happens when using the command line:

 > php -r 'var_dump("lol");'
 Command line code:1:
 string(3) "lol"

While I'm just used to "string(3) "lol"" being printed.

This is not a showstopper but broke a couple of my unit-tests where I needed to compare some output from an API which is printed using var_dump(). I first thought it could be related to xdebug, but couldn't find any directive that seemd to be related to this problem.

Any hint what is causing this is appreciated.


Solution

  • You have xdebug enabled.

    One of the new features relates to one of the first things that I added in the original Xdebug: making the var_dump() output "pretty". Xdebug replaces PHP's standard var_dump() function with its own version, as long as the xdebug.overload_var_dump setting is not set to 0


    Xdebug 2.3 enhances the overloading of var_dump() with the inclusion of the file name and line number where var_dump() is called at. This has been a long standing feature request.

    Here is my output without xdebug;

    >php -r "var_dump('lol')";
    string(3) "lol"
    

    https://derickrethans.nl/xdebug-2.3-overload-vardump.html