Blame | Last modification | View Log | Download
# sebastian/exporter[](https://github.com/sebastianbergmann/exporter/actions)[](https://shepherd.dev/github/sebastianbergmann/exporter)This component provides the functionality to export PHP variables for visualization.## InstallationYou can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):```composer require sebastian/exporter```If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:```composer require --dev sebastian/exporter```## UsageExporting:```php<?phpuse 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);```## Data TypesExporting simple types:```php<?phpuse SebastianBergmann\Exporter\Exporter;$exporter = new Exporter;// 46print $exporter->export(46);// 4.0print $exporter->export(4.0);// 'hello, world!'print $exporter->export('hello, world!');// falseprint $exporter->export(false);// NANprint $exporter->export(acos(8));// -INFprint $exporter->export(log(0));// nullprint $exporter->export(null);// resource(13) of type (stream)print $exporter->export(fopen('php://stderr', 'w'));// Binary String: 0x000102030405print $exporter->export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));```Exporting complex types:```php<?phpuse SebastianBergmann\Exporter\Exporter;$exporter = new Exporter;/*Array &0 (0 => Array &1 (0 => 11 => 22 => 3)1 => Array &2 (0 => ''1 => 02 => 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);```Compact exports:```php<?phpuse 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...\nspaceprint $exporter->shortenedExport(<<<LONG_STRINGthisisasuperlongstringthatwrapsalotandeatsupalotofspaceLONG_STRING);```