You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP 8.1 introduced a seemingly unintentional BC break in ca94d55 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. ClosesGH-12388. For the test: Co-authored-by: wazelin <contact@sergeimikhailov.com>
* We want to block the serialization and unserialization of DOM classes.
1791
+
* However, using @not-serializable makes the child classes also not serializable, even if the user implements the methods.
1792
+
* So instead, we implement the methods wherein we throw exceptions.
1793
+
* The reason we choose these methods is because:
1794
+
* - If the user implements __serialize / __unserialize, the respective throwing methods are not called.
1795
+
* - If the user implements __sleep / __wakeup, then it's also not a problem because they will not enter the throwing methods.
1796
+
*/
1797
+
1798
+
PHP_METHOD(DOMNode, __sleep)
1799
+
{
1800
+
zend_throw_exception_ex(NULL, 0, "Serialization of '%s' is not allowed, unless serialization methods are implemented in a subclass", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name));
1801
+
RETURN_THROWS();
1802
+
}
1803
+
1804
+
PHP_METHOD(DOMNode, __wakeup)
1805
+
{
1806
+
zend_throw_exception_ex(NULL, 0, "Unserialization of '%s' is not allowed, unless unserialization methods are implemented in a subclass", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name));
Deprecated: SerializableDomDocumentSerializeUnserialize implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in %s on line %d
0 commit comments