Closed MarkBerube closed 5 months ago
Thanks for the great bug report, @MarkBerube !
Provide a possible solution
Another option to consider: We could potentially skip mysqli_result
objects for PHP 8.1 and throw a warning.
I'm not sure of the use case to search/replace inside of a mysqli_result
object. It seems like it'd be much more preferable to throw a warning and continue command execution.
💡 If you run into this issue and need a quick workaround, try this:
$ wp db query "SELECT option_name FROM wp_options WHERE option_value LIKE '%mysqli_result%'"
_wpallimport_session_98_
$ wp option delete _wpallimport_session_98_
Success: Deleted '_wpallimport_session_98_' option.
$ wp search-replace old new --all-tables --report-changed-only --skip-columns=guid,user_email,comment_author_email,display_meta,domain,referrer
Success: Made 10797 replacements.
I was wondering why we had mysqli_result
objects in the database in the first place. An old version of the WP All Import plugin stored them as part of its logs in the database. So finding and deleting them not only resolved the issue but additionally cleaned up the database. 👍
Of course, we should still avoid the error with the proposed PR. 🙂
you could also be super specific about the empty mysqli_result
objects if you want to be safe since PHP serializes objects the same way every time:
where option_value REGEXP 'O:13:"mysqli_result":5:{s:13:"current_field";N;s:11:"field_count";N;s:7:"lengths";N;s:8:"num_rows";N;s:4:"type";N;}';
🔨
Saved my day :)
Bug Report
Describe the current, buggy behavior
On PHP 8.1 there was a significant change on how data is deserialized into objects and it can cause fatal errors on search & replace. In PHP 8.0 and older if you deserialized an empty
mysqli_result
object, no big deal. However in PHP 8.1 the typehinting is far more strict & if you provide anull
value on a object that is typed likeint
you'll find this error on deserialization:This has potential to block anybody from upgrading to PHP 8.1+ with wp-cli since it is really quite common to find
mysqli_result
objects in WP DB due to plugins.Describe how other contributors can replicate this bug
To replicate this bug, bring down the following docker environment: https://gist.github.com/MarkBerube/3c79f30551cb650d70b0822afed04cb0
run the following
should produce the following stdout:
Describe what you would expect as the correct outcome
No PHP fatal errors on search & replace.
Let us know what environment you are running this on
Provide a possible solution The problem is serializing between older PHP versions, specially with objects like
mysqli_result
that are strongly typed now. Don't expect there to be an easy way to clean all objects that folks leave in their DB but maybe the simple ones could be targeted via regexProvide additional context/Screenshots original report that was found: https://github.com/php/php-src/issues/10893 potential fix for future: https://github.com/php/php-src/pull/6587