1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-24 18:16:10 +02:00

Avoid throwing an exception when the toString fails (#1868)

This commit is contained in:
Vincent Langlet
2024-04-12 10:47:57 +02:00
committed by GitHub
parent a693dc25b0
commit c4ba76aeae
2 changed files with 25 additions and 5 deletions

View File

@@ -210,8 +210,14 @@ class NormalizerFormatter implements FormatterInterface
$accessor = new \ArrayObject($data);
$value = (string) $accessor['__PHP_Incomplete_Class_Name'];
} elseif (method_exists($data, '__toString')) {
/** @var string $value */
$value = $data->__toString();
try {
/** @var string $value */
$value = $data->__toString();
} catch (\Throwable) {
// if the toString method is failing, use the default behavior
/** @var null|scalar|array<mixed[]|scalar|null> $value */
$value = json_decode($this->toJson($data, true), true);
}
} else {
// the rest is normalized by json encoding and decoding it
/** @var null|scalar|array<mixed[]|scalar|null> $value */