提供导出 PHP 变量以进行可视化的功能
composer require sebastian/exporter
如果您仅在开发阶段需要此库,例如运行项目的测试套件,则应将其添加为开发时依赖项:
composer require --dev sebastian/exporter
## 使用 导出:php
<?php declare(strict_types=1);
use SebastianBergmann\Exporter\Exporter;
$exporter = new Exporter;
/* Exception Object #4 ( 'message' => '', 'string' => '', 'code' => 0, 'file' => '/home/sebastianbergmann/test.php', 'line' => 34, 'previous' => null, ) */
print $exporter->export(new Exception);
## 数据类型 导出简单类型:
…
导出复杂类型:
…
紧凑型导出:php
<?php declare(strict_types=1);
use SebastianBergmann\Exporter\Exporter;
$exporter = new Exporter;
// [] print $exporter->shortenedExport([]);
// [...] print $exporter->shortenedExport([1, 2, 3, 4, 5]);
// stdClass Object () print $exporter->shortenedExport(new stdClass);
// Exception Object (...) print $exporter->shortenedExport(new Exception);
// 'this\nis\na\nsuper\nlong\nstr...nspace' print $exporter->shortenedExport( <<<LONG_STRING this is a super long string that wraps a lot and eats up a lot of space LONG_STRING );
默认情况下,对象按属性进行导出。实现 `ObjectExporter` 接口可控制某类对象的表示方式: