[php-src] Issue #10893: PHP 8.1 fatals when attempting to unserialize empty mysqli_result from PHP 8.0
| From: | brandonpayton | Date: | Tue, 21 Mar 2023 00:38:38 +0000 |
| Subject: | [php-src] Issue #10893: PHP 8.1 fatals when attempting to unserialize empty mysqli_result from PHP 8.0 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243948@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10893
Author: 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
<?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_