-
Notifications
You must be signed in to change notification settings - Fork 7.9k
PHP 8.1 fatals when attempting to unserialize empty mysqli_result from PHP 8.0 #10893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
mysqli_result isn't reliably serializable to begin with. https://www.php.net/manual/en/function.serialize.php
And I don't know if it's still the case, but it used to be said that serialized representations are not guaranteed to be compatible between PHP versions. |
AFAIK we never provided any guarantee that serialization/unserialization worked across versions. |
For the sake of discussion... In practice, it seems desirable for serialization/unserialization to work across versions because it reduces the friction and risk with upgrading to new PHP versions. WordPress, in particular, stores serialized representations of PHP data and unserializes that data all the time. When we switch sites to new major/minor PHP versions on WordPress.com, we do not worry about WordPress breaking due to unserialization fatals. Perhaps serialization of Is there a point at which it might make sense to make such a guarantee, at least for certain core types? |
The "certain core types" do make the guarantee - more or less - by implementing Serializable or whatever else is required. The ones that don't either (a) should, and it's valid to request it be added, or (b) should not, and they shouldn't be serialized at all. However, there are still some internal serialization representations that are still in play. And yes, mysqli_result is a weird thing to serialize... Honestly, for a need to generically serialize data, I'd say that JSON is the way to go: take the data you want and store it in the format you want. That said, developers will still eventually face the same sorts of problems as PHP has: sometimes the serialization format needs to change. |
Thanks for the helpful discussion, @damianwadley! I'll go ahead and close this. |
@brandonpayton I'm curious how you worked around this on your side? I'm seeing the same issue as well when using WP CLI with PHP 8.2. |
@vikramparth, this response is quite late, but in our case, we just deleted the WordPress options with the problematic values (they were no longer relevant anyway) and re-ran our processing. |
Description
Given a mysqli connection
$mysqli_connection
, an emptymysqli_result
instance can be created likenew mysqli_result( $mysqli_connection )
. Such an empty instance is serialized differently between PHP 8.0 and PHP 8.1, and PHP 8.1 fatals when attempting to deserialize the PHP 8.0 representation.In PHP 8.0,
serialize( new mysqli_result( $mysqli_connection ) )
yields the string: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;}
The following code in PHP 8.1:
Resulted in this output (tested via WP-CLI's
wp shell
command):But I expected output like this instead:
PHP 8.0 produces output like that above, but PHP 8.1 fatals. This means that PHP 8.1 can fatal when attempting to unserialize data serialized by PHP 8.0.
PHP Version
PHP 8.1.17
Operating System
No response
The text was updated successfully, but these errors were encountered: