sebastian / exporter
提供导出PHP变量进行可视化的功能
6.1.3
2024-07-03 04:56 UTC
Requires
- php: >=8.2
- ext-mbstring: *
- sebastian/recursion-context: ^6.0
Requires (Dev)
- phpunit/phpunit: ^11.2
This package is auto-updated.
Last update: 2024-09-07 12:46:03 UTC
README
sebastian/exporter
此组件提供了导出PHP变量进行可视化的功能。
安装
您可以使用Composer将此库添加为您的项目的本地、特定项目的依赖项。
composer require sebastian/exporter
如果您仅需要在开发期间使用此库,例如运行项目的测试套件,那么您应将其添加为开发时依赖项。
composer require --dev sebastian/exporter
用法
导出
<?php use SebastianBergmann\Exporter\Exporter; $exporter = new Exporter; /* Exception Object &0000000078de0f0d000000002003a261 ( 'message' => '' 'string' => '' 'code' => 0 'file' => '/home/sebastianbergmann/test.php' 'line' => 34 'previous' => null ) */ print $exporter->export(new Exception);
数据类型
导出简单类型
<?php use SebastianBergmann\Exporter\Exporter; $exporter = new Exporter; // 46 print $exporter->export(46); // 4.0 print $exporter->export(4.0); // 'hello, world!' print $exporter->export('hello, world!'); // false print $exporter->export(false); // NAN print $exporter->export(acos(8)); // -INF print $exporter->export(log(0)); // null print $exporter->export(null); // resource(13) of type (stream) print $exporter->export(fopen('php://stderr', 'w')); // Binary String: 0x000102030405 print $exporter->export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
导出复杂类型
<?php use SebastianBergmann\Exporter\Exporter; $exporter = new Exporter; /* Array &0 ( 0 => Array &1 ( 0 => 1 1 => 2 2 => 3 ) 1 => Array &2 ( 0 => '' 1 => 0 2 => false ) ) */ print $exporter->export(array(array(1,2,3), array("",0,FALSE))); /* Array &0 ( 'self' => Array &1 ( 'self' => Array &1 ) ) */ $array = array(); $array['self'] = &$array; print $exporter->export($array); /* stdClass Object &0000000003a66dcc0000000025e723e2 ( 'self' => stdClass Object &0000000003a66dcc0000000025e723e2 ) */ $obj = new stdClass(); $obj->self = $obj; print $exporter->export($obj);
紧凑导出
<?php use SebastianBergmann\Exporter\Exporter; $exporter = new Exporter; // Array () print $exporter->shortenedExport(array()); // Array (...) print $exporter->shortenedExport(array(1,2,3,4,5)); // stdClass Object () print $exporter->shortenedExport(new stdClass); // Exception Object (...) print $exporter->shortenedExport(new Exception); // this\nis\na\nsuper\nlong\nstring\nt...\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 );