yii\helpers\BaseVarDumper::dumpAsString PHP Method

dumpAsString() public static method

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 dumpAsString ( mixed $var, integer $depth = 10, boolean $highlight = false ) : string
$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;
    }

Usage Example

Example #1
0
 /**
  * @return int
  */
 public function startup()
 {
     $bot = new Bot("qBot");
     /*
      * plugins
      */
     $bot->loadPlugin("Log", array('dir' => 'C:\\OpenServer\\domains\\skypebot\\logs', 'chat_topic_filter' => null, 'chat_id_filter' => null));
     $bot->loadPlugin("MessageReader", array('chat_topic_filter' => null, 'chat_id_filter' => null));
     $bot->loadPlugin("ChatOpener", array('chat_topic_filter' => null, 'chat_id_filter' => null));
     $bot->loadPlugin("PingPong", array('chat_topic_filter' => null, 'chat_id_filter' => null));
     $bot->loadPlugin("DriverService", array('chat_topic_filter' => null, 'chat_id_filter' => null));
     $bot->scenario = Bot::SCENARIO_DEFAULT;
     $bot->_run();
     if ($bot->run()) {
         $this->stdout('Success create user', Console::NORMAL);
         return self::EXIT_CODE_NORMAL;
     }
     if ($bot->hasErrors()) {
         $this->stdout(BaseVarDumper::dumpAsString($bot->getErrors()), Console::BG_YELLOW);
     }
     return self::EXIT_CODE_ERROR;
 }