[php-src] PR #12388: Fix GH-8996: DOMNode serialization on PHP ^8.1
| From: | nielsdos | Date: | Sun, 08 Oct 2023 22:35:35 +0000 |
| Subject: | [php-src] PR #12388: Fix GH-8996: DOMNode serialization on PHP ^8.1 | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-23814@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/12388
Author: nielsdos
I have a solution to the problem that can work on 8.1.
PHP 8.1 introduced a seemingly unintentional BC break in ca94d55a19 by blocking the
(un)serialization of DOM objects.
This was done because the serialization never really worked and just resulted in an empty object,
which upon unserialization just resulted in an object that you can't use.
Users can however implement their own serialization methods, but the commit made that impossible as
the ACC flag gets passed down to the child class. An approach was tried in #10307 with a new ACC
flag to selectively allow serialization with subclasses if they implement the right methods.
However, that was found to be too ad hoc.
Instead, let's abuse how the __sleep and __wakeup methods work to throw the exception instead.
If the child class implements the __serialize / __unserialize method, then the throwing methods
won't be called. Similarly, if the child class implements __sleep and __wakeup, then
they're overridden and it doesn't matter that they throw.
For the user, this PR has the exact same behaviour for (sub)classes that don't implement the
serialization methods: an exception will be thrown. For code that previously implemented subclasses
with these methods, this approach will make that code work again. This approach should be both BC
preserving and unbreak user's code.
For the test:
Co-authored-by: wazelin <contact@sergeimikhailov.com>