Skip to content
PHP Ecosystem
Explore

BaseVarDumper

API reference › yii › helpers › BaseVarDumper

classyii\helpers\BaseVarDumper
Since2.0
Sourceframework/helpers/BaseVarDumper.php
1 subclass

BaseVarDumper provides concrete implementation for VarDumper.

Do not use BaseVarDumper. Use VarDumper instead.

MethodDescriptionDefined by
dump() staticDisplays a variable.BaseVarDumper
dumpAsString() staticDumps a variable in terms of a string.BaseVarDumper
export() staticExports a variable as a string representation.BaseVarDumper
public static function dump(mixed $var, int $depth = 10, bool $highlight = false): mixed

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.

Parameters

ParameterTypeDescription
$varmixedVariable to be dumped
$depthintMaximum depth that the dumper should go into the variable. Defaults to 10.
$highlightboolWhether the result should be syntax-highlighted

Returns

mixed

public static function dumpAsString(mixed $var, int $depth = 10, bool $highlight = false): string

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.

Parameters

ParameterTypeDescription
$varmixedVariable to be dumped
$depthintMaximum depth that the dumper should go into the variable. Defaults to 10.
$highlightboolWhether the result should be syntax-highlighted

Returns

string: The string representation of the variable

public static function export(mixed $var): string

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.

Parameters

ParameterTypeDescription
$varmixedThe variable to be exported.

Returns

string: A string representation of the variable