Exclude trace from exceptions/errors for performance reasons (#24)

This commit is contained in:
Bernhard Schussek 2019-08-11 14:37:44 +02:00 committed by Sebastian Bergmann
parent dd6dc4676b
commit 71e429fb3a
3 changed files with 33 additions and 1 deletions

View File

@ -22,7 +22,6 @@ Exception Object &0000000078de0f0d000000002003a261 (
'code' => 0
'file' => '/home/sebastianbergmann/test.php'
'line' => 34
'trace' => Array &0 ()
'previous' => null
)
*/

View File

@ -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"

View File

@ -168,6 +168,32 @@ EOF
'',
"''"
],
'export Exception without trace' => [
new \Exception('The exception message', 42),
<<<EOF
Exception Object &%x (
'message' => '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),
<<<EOF
Error Object &%x (
'message' => 'The exception message'
'string' => ''
'code' => 42
'file' => '%s/tests/ExporterTest.php'
'line' => %d
'previous' => null
)
EOF
],
];
}