Skip to content

Commit aef6539

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix GH-8068: mysqli_fetch_object creates inaccessible properties
2 parents 33eec37 + ef29ddc commit aef6539

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
classes). (ilutov)
1515
. Fixed bug GH-8142 (Compilation error on cygwin). (David Carlier)
1616

17+
- MySQLi:
18+
. Fixed bug GH-8068 (mysqli_fetch_object creates inaccessible properties).
19+
(cmb)
20+
1721
- Pcntl:
1822
. Fixed bug GH-8142 (Compilation error on cygwin). (David Carlier)
1923

ext/mysqli/mysqli.c

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

11571157
object_init_ex(return_value, ce);
1158+
HashTable *prop_table = zend_symtable_to_proptable(Z_ARR(dataset));
1159+
zval_ptr_dtor(&dataset);
11581160
if (!ce->default_properties_count && !ce->__set) {
1159-
Z_OBJ_P(return_value)->properties = Z_ARR(dataset);
1161+
Z_OBJ_P(return_value)->properties = prop_table;
11601162
} else {
1161-
zend_merge_properties(return_value, Z_ARRVAL(dataset));
1162-
zval_ptr_dtor(&dataset);
1163+
zend_merge_properties(return_value, prop_table);
1164+
zend_array_release(prop_table);
11631165
}
11641166

11651167
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)