Skip to content

PHP 8.1 fatals when attempting to unserialize empty mysqli_result from PHP 8.0Β #10893

@brandonpayton

Description

@brandonpayton

Description

Given a mysqli connection $mysqli_connection, an empty mysqli_result instance can be created like new 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:

<?php
var_dump(
    unserialize(
        '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;}'
    )
);

Resulted in this output (tested via WP-CLI's wp shell command):

Fatal error: Uncaught TypeError: Cannot assign null to property mysqli_result::$current_field of type int in phar:///usr/local/bin/wp-cli/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(46) : eval()'d code:1

But I expected output like this instead:

object(mysqli_result)#8072 (0) {
}

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions