Skip to content

Commit efab5aa

Browse files
angeljqvSeldaek
andauthored
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 <[email protected]>
1 parent f049cfd commit efab5aa

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

src/Monolog/Handler/Handler.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,10 @@ public function __destruct()
4444
}
4545
}
4646

47-
public function __sleep()
47+
public function __serialize(): array
4848
{
4949
$this->close();
5050

51-
$reflClass = new \ReflectionClass($this);
52-
53-
$keys = [];
54-
foreach ($reflClass->getProperties() as $reflProp) {
55-
if (!$reflProp->isStatic()) {
56-
$keys[] = $reflProp->getName();
57-
}
58-
}
59-
60-
return $keys;
51+
return (array) $this;
6152
}
6253
}

tests/Monolog/Handler/StreamHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testClose()
6767

6868
/**
6969
* @covers Monolog\Handler\StreamHandler::close
70-
* @covers Monolog\Handler\Handler::__sleep
70+
* @covers Monolog\Handler\Handler::__serialize
7171
*/
7272
public function testSerialization()
7373
{

0 commit comments

Comments
 (0)