Why does var_dump show filename and line number?

前端 未结 2 1846
灰色年华
灰色年华 2020-12-19 01:06

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

2条回答
  •  再見小時候
    2020-12-19 01:41

    If you don't want the extra data produced by var_dump(), you can use var_export() which will show a stripped-down output.

    Here is a test case:

    $values = [
        0 => '',
        1 => 'foo',
        2 => null,
        3 => false,
        4 => true,
        5 => 0,
        6 => new stdClass
    ];
    

    var_dump():

    foreach ($values as $value) {
        echo var_dump($value) . PHP_EOL;
    }
    

    Output of plain old PHP:

    string(0) ""
    string(3) "foo"
    NULL
    bool(false)
    bool(true)
    int(0)
    object(stdClass)#1 (0) {
    }
    

    Output of PHP XDEBUG:

    /var/www/html/test.php:12:string '' (length=0)
    /var/www/html/test.php:12:string 'foo' (length=3)
    /var/www/html/test.php:12:null
    /var/www/html/test.php:12:boolean false
    /var/www/html/test.php:12:boolean true
    /var/www/html/test.php:12:int 0
    /var/www/html/test.php:12:
    object(stdClass)[1]
    

    var_export():

    foreach ($values as $value) {
        echo var_export($value) . PHP_EOL;
    }
    

    Output of PHP (plain or with XDEBUG)

    ''
    'foo'
    NULL
    false
    true
    0
    (object) array(
    )
    

提交回复
热议问题