diff --git a/README.md b/README.md index 7bbef50..4c838ab 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Exception Object &0000000078de0f0d000000002003a261 ( 'code' => 0 'file' => '/home/sebastianbergmann/test.php' 'line' => 34 - 'trace' => Array &0 () 'previous' => null ) */ diff --git a/src/Exporter.php b/src/Exporter.php index 8309ee6..0e4a165 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -146,6 +146,13 @@ class Exporter $array = []; foreach ((array) $value as $key => $val) { + // Exception traces commonly reference hundreds to thousands of + // objects currently loaded in memory. Including them in the result + // has a severe negative performance impact. + if ("\0Error\0trace" === $key || "\0Exception\0trace" === $key) { + continue; + } + // properties are transformed to keys in the following way: // private $property => "\0Classname\0property" // protected $property => "\0*\0property" diff --git a/tests/ExporterTest.php b/tests/ExporterTest.php index 5da4f4c..a9aded0 100644 --- a/tests/ExporterTest.php +++ b/tests/ExporterTest.php @@ -168,6 +168,32 @@ EOF '', "''" ], + 'export Exception without trace' => [ + new \Exception('The exception message', 42), + << 'The exception message' + 'string' => '' + 'code' => 42 + 'file' => '%s/tests/ExporterTest.php' + 'line' => %d + 'previous' => null +) +EOF + ], + 'export Error without trace' => [ + new \Error('The exception message', 42), + << 'The exception message' + 'string' => '' + 'code' => 42 + 'file' => '%s/tests/ExporterTest.php' + 'line' => %d + 'previous' => null +) +EOF + ], ]; }