b2r/simple-dump

v0.1.0 2017-02-20 04:21 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:30:32 UTC


README

简单的 var_dump 包装器

Build Status

摘要

  • 最小化 var_dump 结果
  • 注册全局函数 pfunction($value...): void 输出dump结果
  • 注册全局函数 psfunction($value...): string 获取dump字符串

用法

use b2r\Component\SimpleDump\SimpleDump;

// get as string
$server = SimpleDump::dump($_SERVER);

// echo
SimpleDump::display($_SERVER);

// Register global function `p` and `ps`
SimpleDump::init();

// get as string
$server = ps($_SERVER);

// echo
p($_SERVER);

比较

// Register global function `p` and `ps`
b2r\Component\SimpleDump\SimpleDump::init();

# Store
$value = [
    'string' => 'string',
    'int'    => 1,
    'float'  => 1.0,
    'true'   => true,
    'false'  => false,
    'null'   => null,
];
$value['object'] = (object)$value;

# Echo
echo "------------------------------------------------------------\n";
p($value);
echo "------------------------------------------------------------\n";
var_dump($value);

结果

------------------------------------------------------------
array(7) {
  ["string"]=> string(6) "string"
  ["int"]=> int(1)
  ["float"]=> float(1)
  ["true"]=> bool(true)
  ["false"]=> bool(false)
  ["null"]=> NULL
  ["object"]=> object(stdClass)#3 (6) {
    ["string"]=> string(6) "string"
    ["int"]=> int(1)
    ["float"]=> float(1)
    ["true"]=> bool(true)
    ["false"]=> bool(false)
    ["null"]=> NULL
  }
}
------------------------------------------------------------
array(7) {
  ["string"]=>
  string(6) "string"
  ["int"]=>
  int(1)
  ["float"]=>
  float(1)
  ["true"]=>
  bool(true)
  ["false"]=>
  bool(false)
  ["null"]=>
  NULL
  ["object"]=>
  object(stdClass)#3 (6) {
    ["string"]=>
    string(6) "string"
    ["int"]=>
    int(1)
    ["float"]=>
    float(1)
    ["true"]=>
    bool(true)
    ["false"]=>
    bool(false)
    ["null"]=>
    NULL
  }
}