1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 19:00:20 +02:00

Fix fatal error in NormalizeFormatter: method_exists(): The script tried to execute a method or access a property of an incomplete object.

Closes #1833
Fixes #1834
This commit is contained in:
Egor Korobov
2023-09-08 17:40:20 +03:00
committed by Jordi Boggiano
parent 70e1c2f405
commit ed80d53ab2
2 changed files with 17 additions and 0 deletions

View File

@@ -174,6 +174,9 @@ class NormalizerFormatter implements FormatterInterface
if ($data instanceof \JsonSerializable) {
/** @var null|scalar|array<array|scalar|null> $value */
$value = $data->jsonSerialize();
} elseif (\get_class($data) === '__PHP_Incomplete_Class') {
$accessor = new \ArrayObject($data);
$value = $accessor['__PHP_Incomplete_Class_Name'];
} elseif (method_exists($data, '__toString')) {
/** @var string $value */
$value = $data->__toString();

View File

@@ -415,6 +415,20 @@ class NormalizerFormatterTest extends TestCase
);
}
public function testCanNormalizeIncompleteObject(): void
{
$serialized = "O:17:\"Monolog\TestClass\":1:{s:23:\"\x00Monolog\TestClass\x00name\";s:4:\"test\";}";
$object = unserialize($serialized);
$formatter = new NormalizerFormatter();
$record = ['context' => ['object' => $object]];
$result = $formatter->format($record);
$this->assertEquals([
'__PHP_Incomplete_Class' => 'Monolog\\TestClass',
], $result['context']['object']);
}
private function throwHelper($arg)
{
throw new \RuntimeException('Thrown');