Skip to content

Commit

Permalink
Fixed #5559, The ZendArray::to_array() function must duplicate the ma…
Browse files Browse the repository at this point in the history
…p's keys.
  • Loading branch information
matyhtf committed Nov 12, 2024
1 parent c0ebcb1 commit 48d7851
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ void ZendArray::to_array(zval *return_value) {
ArrayItem *item = (ArrayItem *) tmp;
item->fetch(&value);
if (key) {
zend_hash_add(Z_ARR_P(return_value), key, &value);
zend_hash_str_add(Z_ARR_P(return_value), ZSTR_VAL(key), ZSTR_LEN(key), &value);
} else {
zend_hash_index_add(Z_ARR_P(return_value), index, &value);
}
Expand Down
24 changes: 24 additions & 0 deletions tests/swoole_thread/map2array.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
swoole_thread: map to array
--SKIPIF--
<?php
require __DIR__ . '/../include/skipif.inc';
skip_if_nts();
?>
--FILE--
<?php

use Swoole\Thread\Map;

require __DIR__ . '/../include/bootstrap.php';

$LURDATE = new Map;
$time = 'abc';
$LURDATE[$time] = new Map(["saaa" => 1111]);
$ls = $LURDATE[$time]->toArray();
foreach ($ls as $k => $v) {
unset($LURDATE[$time][$k]);
}
unset($LURDATE[$time]);
?>
--EXPECTF--

0 comments on commit 48d7851

Please sign in to comment.