Skip to content

Commit 035105b

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix GH-11451: Invalid associative array containing duplicate keys
2 parents 08f6072 + 29a96e0 commit 035105b

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,9 @@ PHP_METHOD(SQLite3Result, fetchArray)
19851985
Z_ADDREF(data);
19861986
}
19871987
}
1988-
zend_symtable_add_new(Z_ARR_P(return_value), result_obj->column_names[i], &data);
1988+
/* Note: we can't use the "add_new" variant here instead of "update" because
1989+
* when the same column name is encountered, the last result should be taken. */
1990+
zend_symtable_update(Z_ARR_P(return_value), result_obj->column_names[i], &data);
19891991
}
19901992
}
19911993
break;

ext/sqlite3/tests/gh11451.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-11451 (Invalid associative array containing duplicate keys)
3+
--EXTENSIONS--
4+
sqlite3
5+
--FILE--
6+
<?php
7+
var_dump((new SQLite3(':memory:'))
8+
->query('SELECT 1 AS key, 2 AS key')
9+
->fetchArray(SQLITE3_ASSOC));
10+
11+
var_dump((new SQLite3(':memory:'))
12+
->query('SELECT 0 AS dummy, 1 AS key, 2 AS key')
13+
->fetchArray(SQLITE3_ASSOC));
14+
?>
15+
--EXPECT--
16+
array(1) {
17+
["key"]=>
18+
int(2)
19+
}
20+
array(2) {
21+
["dummy"]=>
22+
int(0)
23+
["key"]=>
24+
int(2)
25+
}

0 commit comments

Comments
 (0)