2 followers

Class yii\helpers\VarDumper

Inheritanceyii\helpers\VarDumper » yii\helpers\BaseVarDumper
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/helpers/VarDumper.php

VarDumper is intended to replace the buggy PHP function var_dump and print_r.

It can correctly identify the recursively referenced objects in a complex object structure. It also has a recursive depth control to avoid indefinite recursive display of some peculiar variables.

VarDumper can be used as follows,

VarDumper::dump($var);

Public Methods

Hide inherited methods

Method Description Defined By
dump() Displays a variable. yii\helpers\BaseVarDumper
dumpAsString() Dumps a variable in terms of a string. yii\helpers\BaseVarDumper
export() Exports a variable as a string representation. yii\helpers\BaseVarDumper

Method Details

Hide inherited methods

dump() public static method

Defined in: yii\helpers\BaseVarDumper::dump()

Displays a variable.

This method achieves the similar functionality as var_dump and print_r but is more robust when handling complex objects such as Yii controllers.

public static void dump ( $var, $depth 10, $highlight false )
$var mixed

Variable to be dumped

$depth integer

Maximum depth that the dumper should go into the variable. Defaults to 10.

$highlight boolean

Whether the result should be syntax-highlighted

                public static function dump($var, $depth = 10, $highlight = false)
{
    echo static::dumpAsString($var, $depth, $highlight);
}

            
dumpAsString() public static method

Defined in: yii\helpers\BaseVarDumper::dumpAsString()

Dumps a variable in terms of a string.

This method achieves the similar functionality as var_dump and print_r but is more robust when handling complex objects such as Yii controllers.

public static string dumpAsString ( $var, $depth 10, $highlight false )
$var mixed

Variable to be dumped

$depth integer

Maximum depth that the dumper should go into the variable. Defaults to 10.

$highlight boolean

Whether the result should be syntax-highlighted

return string

The string representation of the variable

                public static function dumpAsString($var, $depth = 10, $highlight = false)
{
    self::$_output = '';
    self::$_objects = [];
    self::$_depth = $depth;
    self::dumpInternal($var, 0);
    if ($highlight) {
        $result = highlight_string("<?php\n" . self::$_output, true);
        self::$_output = preg_replace('/&lt;\\?php<br \\/>/', '', $result, 1);
    }
    return self::$_output;
}

            
export() public static method

Defined in: yii\helpers\BaseVarDumper::export()

Exports a variable as a string representation.

The string is a valid PHP expression that can be evaluated by PHP parser and the evaluation result will give back the variable value.

This method is similar to var_export(). The main difference is that it generates more compact string representation using short array syntax.

It also handles objects by using the PHP functions serialize() and unserialize().

PHP 5.4 or above is required to parse the exported value.

public static string export ( $var )
$var mixed

The variable to be exported.

return string

A string representation of the variable

                public static function export($var)
{
    self::$_output = '';
    self::exportInternal($var, 0);
    return self::$_output;
}