1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-27 18:51:34 +01:00

Fix PHP 8.5 __sleep deprecation (#1997)

This patch breaks any implementation of __sleep in child classes/user handlers. Should be warned in the release notes.

Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
This commit is contained in:
angeljqv
2025-10-24 03:02:31 -05:00
committed by GitHub
parent f049cfdcda
commit efab5aabaf
2 changed files with 3 additions and 12 deletions

View File

@@ -44,19 +44,10 @@ abstract class Handler implements HandlerInterface
} }
} }
public function __sleep() public function __serialize(): array
{ {
$this->close(); $this->close();
$reflClass = new \ReflectionClass($this); return (array) $this;
$keys = [];
foreach ($reflClass->getProperties() as $reflProp) {
if (!$reflProp->isStatic()) {
$keys[] = $reflProp->getName();
}
}
return $keys;
} }
} }

View File

@@ -67,7 +67,7 @@ class StreamHandlerTest extends \Monolog\Test\MonologTestCase
/** /**
* @covers Monolog\Handler\StreamHandler::close * @covers Monolog\Handler\StreamHandler::close
* @covers Monolog\Handler\Handler::__sleep * @covers Monolog\Handler\Handler::__serialize
*/ */
public function testSerialization() public function testSerialization()
{ {