[php-src] Issue #8996: DOMNode serialization on PHP ^8.1

From: Date: Wed, 13 Jul 2022 11:47:25 +0000
Subject: [php-src] Issue #8996: DOMNode serialization on PHP ^8.1
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241919@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8996 Author: wazelin ### Description The following code: ```php <?php class SerializableDomDocument extends DOMDocument { private $xmlData; public function __sleep(): array { $this->xmlData = $this->saveXML(); return ['xmlData']; } public function __wakeup(): void { $this->loadXML($this->xmlData); } } $dom = new SerializableDomDocument('1.0', 'UTF-8'); $dom->loadXML('<tag>value</tag>'); $serialized = serialize($dom); $unserialized = unserialize($serialized); echo "Serialized:\n-----------\n$serialized\n-----------\nRestored:\n-----------\n{$unserialized->saveXml()}"; ``` Resulted in this output: ``` Fatal error: Uncaught Exception: Serialization of 'SerializableDomDocument' is not allowed in script.php:20 Stack trace: #0 script.php(20): serialize(Object(SerializableDomDocument)) #1 {main} thrown in script.php on line 20 ``` But I expected this output instead: ``` Serialized: ----------- O:23:"SerializableDomDocument":1:{s:32:"SerializableDomDocumentxmlData";s:39:"<?xml version="1.0"?> <tag>value</tag> ";} ----------- Restored: ----------- <?xml version="1.0"?> <tag>value</tag> ``` It appears to be sort of an _expected_ behavior of PHP 8.1 due to https://github.com/php/php-src/commit/ca94d55a19da2c92f9812d3f2dd8172fb8b9c52b, but I would still expect: 1. The change to be marked as a breaking one in the PHP 8.1 release notes 2. Allow serialization _if_ the descendant class explicitly states it is serializable by providing __serialize() / __deserialize() or __sleep() / __wakeup() method. ### PHP Version 8.1.0 - 8.1.8 ### Operating System _No response_

« previous php.bugs (#241919) next »