ghostff/dump7

php var_dump的精美版本。此类可以显示一个或多个表达式的结构化信息,包括其类型和值。

v2.0.2 2021-01-12 11:48 UTC

This package is auto-updated.

Last update: 2024-09-07 04:03:49 UTC


README

php var_dump的精美版本。此类可以显示一个或多个表达式的结构化信息,包括其类型和值。

查看Dump5以获取PHP 5+版本

安装

您可以选择下载最新的发布版本作为独立版本,或者您可以使用Composer

composer require ghostff/dump7
"require": {
    "ghostff/dump7": "^1.0"
}

显示标志

您可以使用文档块标志简单地隐藏或显示某些对象的属性

/**
* @dumpignore-inheritance
* @dumpignore-inherited-class
* @dumpignore-private
* @dumpignore-public
* @dumpignore-public
*/
Class Foo extends Bar {
    /** @dumpignore */
    private ?BigObject $foo = null;
}

用法

class FooBar
{
    private $inherited_int   = 123;
    private $inherited_array = ['string'];
}

class Bar extends FooBar
{
    private $inherited_float = 0.22;
    private $inherited_bool  = 1 == '1';
}

class Foo extends Bar
{
    private $string = 'string';
    protected $int  = 10;
    public $array   = [
        'foo' => 'bar'
    ];
    protected static $bool = false;
}

$string   = 'Foobar';
$array    = ['foo', 'bar'];
$int      = 327626;
$double   = 22.223;
$null     = null;
$bool     = true;
$resource = fopen('LICENSE', 'r');
$m        = microtime(true);

new Dump(new Foo, $string, $array, $int, $double, $null, $bool, [
    'foo' => 'bar',
    'bar' => 'foo',
    [
        'foo' => 'foobar',
        'bar_foo',
        2 => 'foo',
        'foo' => [
            'barbar' => 55,
            'foofoo' => false,
            'foobar' => null,
        ]
    ]
], $resource);

new Dump(1 == '1', 1 === '1');
Dump::safe(...$args); # running on terminal without color capabilities.

替换预定义的颜色

# set($name, [$cgi_color, $cli_color]);
Dump::set('boolean', ['bb02ff', 'purple']);

默认情况下,当Dump在函数内部调用时,调用行设置为函数内部的new Dump而不是函数调用。使用setTraceOffset您可以设置每个调用行的偏移量。

function dump()
{
    Dump::setTraceOffset(2);
    new Dump(...func_get_args()); # Dont use this test.php(line:4) as call line
}

dump('foo', 22, 'bar', true); // Use test.php(line:7) instead

CGI输出

cgi screenshot

CLI(Unix)

cli screenshot

CLI(Windows)

cli screenshot