jacobstr/dumpling

类似于 print_r,但具有深度限制且可安全处理循环引用。

v0.0.3 2014-05-10 03:22 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:44:20 UTC


README

这是一个用于生成变量转储的小工具。PHP 内置的 print_r 在使用复杂的对象图时会出现问题。默认情况下,它还直接输出到 stdout。

最初基于以下代码: http://ca2.php.net/print_r#78851。将其封装并打包以适应 composer 时代。

使用方法

Dumpling

>> echo Dumpling::d($cyclical_line_point_object);

Dumpling\Tests\Line Object (
    [points] => Array (
        [0] => Dumpling\Tests\Point Object (
            [x] => 5
            [y] => 10
            [line] => Nested Dumpling\Tests\Line Object
        )
    )
)

>> echo Dumpling::d(array_slice(debug_backtrace(),0,2),2);

Array (
    [0] => Array (
        [function] => should_dump_a_recursive_object_at_depth_2
        [class] => Dumpling\Tests\DumplingTest
        [object] => Nested Dumpling\Tests\DumplingTest Object
        [type] => ->
        [args] => Nested Array
    )
    [1] => Array (
        [file] => /Users/jacob/Work/dumpling/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php
        [line] => 983
        [function] => invokeArgs
        [class] => ReflectionMethod
        [object] => Nested ReflectionMethod Object
        [type] => ->
        [args] => Nested Array
    )
)

测试

composer install
vendor/bin/phpunit tests/DumplingTest.php