phphttphttp-headersxdebugxdebug-profiler

var_dump() and print_r() output different values


I run this code:

<?php
     $test = $_SERVER['HTTP_HOST'];
     var_dump($test);
     print_r($test);
     die();

I get this output: enter image description here

I run this code:

<?php
     $test = $_SERVER['HTTP_HOST'];
     print_r($test);
     var_dump($test);
     die();

I get this output: enter image description here

Why can't print_r() and var_dump() agree on the value of $test in case 1?

For context on how I arrived here. I am running a laravel/homestead vm box, and I'm using Browsersync. Browsersync creates a proxy (localhost:3000) that I connect to, which points to the laravel/homestead vm (192.168.10.10). The proxy changes the value of the Host header when the request passes through it.


Solution

  • This is an Xdebug bug.

    Solution: disable xdebug.

    Output with xdebug disabled:

    enter image description here