0 追蹤者

類別 yii\helpers\BaseVarDumper

繼承關係yii\helpers\BaseVarDumper
子類別yii\helpers\VarDumper
自版本2.0
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseVarDumper.php

BaseVarDumper 為 yii\helpers\VarDumper 提供具體實作。

請勿使用 BaseVarDumper。請改用 yii\helpers\VarDumper

公開方法

隱藏繼承的方法

方法 描述 定義於
dump() 顯示變數。 yii\helpers\BaseVarDumper
dumpAsString() 以字串形式傾印變數。 yii\helpers\BaseVarDumper
export() 將變數匯出為字串表示形式。 yii\helpers\BaseVarDumper

方法詳情

隱藏繼承的方法

dump() public static method

顯示變數。

此方法實現了類似於 var_dump 和 print_r 的功能,但在處理複雜物件(如 Yii 控制器)時更為穩健。

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

要傾印的變數

$depth integer

傾印器應深入變數的最大深度。預設為 10。

$highlight boolean

結果是否應語法突顯

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

            
dumpAsString() public static method

以字串形式傾印變數。

此方法實現了類似於 var_dump 和 print_r 的功能,但在處理複雜物件(如 Yii 控制器)時更為穩健。

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

要傾印的變數

$depth integer

傾印器應深入變數的最大深度。預設為 10。

$highlight boolean

結果是否應語法突顯

return string

變數的字串表示形式

                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

將變數匯出為字串表示形式。

此字串是一個有效的 PHP 表達式,可以被 PHP 解析器評估,並且評估結果將回傳變數值。

此方法與 var_export() 相似。主要差異在於它使用簡短的陣列語法產生更精簡的字串表示形式。

它還透過使用 PHP 函數 serialize() 和 unserialize() 來處理物件。

需要 PHP 5.4 或以上版本才能解析匯出的值。

public static string export ( $var )
$var mixed

要匯出的變數。

return string

變數的字串表示形式

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