Skip to content

Commit dad214c

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-8068: mysqli_fetch_object creates inaccessible properties
2 parents 6c18287 + aef6539 commit dad214c

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

ext/mysqli/mysqli.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,11 +1139,13 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
11391139
ZVAL_COPY_VALUE(&dataset, return_value);
11401140

11411141
object_init_ex(return_value, ce);
1142+
HashTable *prop_table = zend_symtable_to_proptable(Z_ARR(dataset));
1143+
zval_ptr_dtor(&dataset);
11421144
if (!ce->default_properties_count && !ce->__set) {
1143-
Z_OBJ_P(return_value)->properties = Z_ARR(dataset);
1145+
Z_OBJ_P(return_value)->properties = prop_table;
11441146
} else {
1145-
zend_merge_properties(return_value, Z_ARRVAL(dataset));
1146-
zval_ptr_dtor(&dataset);
1147+
zend_merge_properties(return_value, prop_table);
1148+
zend_array_release(prop_table);
11471149
}
11481150

11491151
if (ce->constructor) {

ext/mysqli/tests/gh8068.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-8068 (mysqli_fetch_object creates inaccessible properties)
3+
--EXTENSION--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require_once 'skipifconnectfailure.inc';
8+
?>
9+
--FILE--
10+
<?php
11+
require_once "connect.inc";
12+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
13+
$mysqli = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14+
$res = $mysqli->query('SELECT 42');
15+
$obj = $res->fetch_object();
16+
var_dump(
17+
$obj,
18+
$obj->{42}
19+
);
20+
?>
21+
--EXPECT--
22+
object(stdClass)#4 (1) {
23+
["42"]=>
24+
string(2) "42"
25+
}
26+
string(2) "42"

0 commit comments

Comments
 (0)