The issue is easily reproduced in the context of parse.php logging, but needs to be audited more carefully to avoid issues in other places.
Steps to replicate the issue:
Using PHP 8.1.5 (Ubuntu):
$ echo "hello" | php bin/parse.php --wt2wt --debug=wts
What happens?:
[... start of WTS trace ...] Exception from line 89 of /home/isa-wmf/gitrepo/parsoid/src/Utils/Utils.php: Serialization of 'Wikimedia\Parsoid\DOM\Element' is not allowed #0 /home/isa-wmf/gitrepo/parsoid/src/Utils/Utils.php(89): serialize() #1 /home/isa-wmf/gitrepo/parsoid/src/Html2Wt/Separators.php(569): Wikimedia\Parsoid\Utils\Utils::clone()
What should have happened instead?:
It shouldn't have crashed.
Note that if debug logging is activated on a Mediawiki install, and if this triggers somehow, it can also make the request crash with a 500, which is less than ideal.
Notes
This is probably related to https://github.com/php/php-src/commit/ca94d55a19da2c92f9812d3f2dd8172fb8b9c52b, which makes DOM classes as not serializable in PHP 8.1. It's unclear to me whether we want to make our subclasses serializable (and whether that will work - https://github.com/php/php-src/issues/8996 seems to indicate it will not work with any build of 8.1) or avoid serializing DOM classes.