diff --git a/src/collections_methods.c b/src/collections_methods.c index 00c7aff..192b3f8 100644 --- a/src/collections_methods.c +++ b/src/collections_methods.c @@ -1251,7 +1251,22 @@ PHP_METHOD(Collection, plusValuesAssign) PHP_METHOD(Collection, putAll) { - + zval* elements; + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_ZVAL(elements) + ZEND_PARSE_PARAMETERS_END(); + ELEMENTS_VALIDATE(elements, ERR_BAD_ARGUMENT_TYPE, return); + zend_array* current = COLLECTION_FETCH_CURRENT(); + SEPARATE_CURRENT_COLLECTION(current); + ZEND_HASH_FOREACH_BUCKET(elements_arr, Bucket* bucket) + Z_TRY_ADDREF(bucket->val); + if (bucket->key) + zend_hash_update(current, bucket->key, &bucket->val); + else if (HT_IS_PACKED(elements_arr)) + zend_hash_next_index_insert(current, &bucket->val); + else + zend_hash_index_update(current, bucket->h, &bucket->val); + ZEND_HASH_FOREACH_END(); } PHP_METHOD(Collection, reduce) diff --git a/tests/038-put-all.phpt b/tests/038-put-all.phpt new file mode 100644 index 0000000..554d89f --- /dev/null +++ b/tests/038-put-all.phpt @@ -0,0 +1,12 @@ +--TEST-- +Test Collection::putAll(). +--FILE-- + 'foo', 'b' => 'bar']; +$array1 = ['a' => 'b', 'c' => 'd', 'e' => 'f']; +$collection = Collection::init($array); +$collection->putAll($array1); +if ($collection->toArray() != array_merge($array, $array1)) + echo 'Collection::putAll() failed.', PHP_EOL; +?> +--EXPECT--