瀏覽代碼

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>
angeljqv 2 月之前
父節點
當前提交
efab5aabaf
共有 2 個文件被更改,包括 3 次插入12 次删除
  1. 2 11
      src/Monolog/Handler/Handler.php
  2. 1 1
      tests/Monolog/Handler/StreamHandlerTest.php

+ 2 - 11
src/Monolog/Handler/Handler.php

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

+ 1 - 1
tests/Monolog/Handler/StreamHandlerTest.php

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