Skip to content

Commit d08735e

Browse files
committed
Make sure empty cases work fine
1 parent 1fc39e1 commit d08735e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ext/spl/spl_iterators.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,8 @@ static zend_result spl_iterator_zip_valid(zend_object_iterator *iter)
30643064
{
30653065
spl_zip_iterator *zip_iterator = (spl_zip_iterator *) iter;
30663066

3067-
for (uint32_t i = 0; i < zip_iterator->iterator_count; i++) {
3067+
uint32_t i = 0;
3068+
for (; i < zip_iterator->iterator_count; i++) {
30683069
spl_zip_iterator_entry *current = &zip_iterator->iterators[i];
30693070
if (spl_zip_iterator_is_obj_entry(current)) {
30703071
if (current->obj_iter->funcs->valid(current->obj_iter) != SUCCESS) {
@@ -3078,7 +3079,7 @@ static zend_result spl_iterator_zip_valid(zend_object_iterator *iter)
30783079
}
30793080
}
30803081

3081-
return SUCCESS;
3082+
return i > 0 ? SUCCESS : FAILURE;
30823083
}
30833084

30843085
/* Invariant: returned array is packed and has all UNDEF elements. */

ext/spl/tests/iterator_zip.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ iterator_zip
33
--FILE--
44
<?php
55

6+
foreach (iterator_zip() as $_) {} // FIXME
7+
8+
foreach (iterator_zip([]) as $x) {
9+
var_dump($x);
10+
}
11+
612
$a = [1, 2, 3];
713
$b = [4, 5, 6];
814

0 commit comments

Comments
 (0)