Skip to content

Commit 5acedab

Browse files
committed
Clarify failure behavior of spl_iterator_apply()
It only fails if it throws, in which case it is meaningless to set a return value.
1 parent de643aa commit 5acedab

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

ext/spl/php_spl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,9 @@ static const zend_function_entry spl_functions[] = {
983983
PHP_FE(class_uses, arginfo_class_uses)
984984
PHP_FE(spl_object_hash, arginfo_spl_object_hash)
985985
PHP_FE(spl_object_id, arginfo_spl_object_id)
986-
#ifdef SPL_ITERATORS_H
987986
PHP_FE(iterator_to_array, arginfo_iterator_to_array)
988987
PHP_FE(iterator_count, arginfo_iterator)
989988
PHP_FE(iterator_apply, arginfo_iterator_apply)
990-
#endif /* SPL_ITERATORS_H */
991989
PHP_FE_END
992990
};
993991
/* }}} */

ext/spl/spl_iterators.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,11 +3573,7 @@ PHP_FUNCTION(iterator_to_array)
35733573
}
35743574

35753575
array_init(return_value);
3576-
3577-
if (spl_iterator_apply(obj, use_keys ? spl_iterator_to_array_apply : spl_iterator_to_values_apply, (void*)return_value) != SUCCESS) {
3578-
zval_ptr_dtor(return_value);
3579-
RETURN_NULL();
3580-
}
3576+
spl_iterator_apply(obj, use_keys ? spl_iterator_to_array_apply : spl_iterator_to_values_apply, (void*)return_value);
35813577
} /* }}} */
35823578

35833579
static int spl_iterator_count_apply(zend_object_iterator *iter, void *puser) /* {{{ */
@@ -3598,9 +3594,11 @@ PHP_FUNCTION(iterator_count)
35983594
RETURN_FALSE;
35993595
}
36003596

3601-
if (spl_iterator_apply(obj, spl_iterator_count_apply, (void*)&count) == SUCCESS) {
3602-
RETURN_LONG(count);
3597+
if (spl_iterator_apply(obj, spl_iterator_count_apply, (void*)&count) == FAILURE) {
3598+
return;
36033599
}
3600+
3601+
RETURN_LONG(count);
36043602
}
36053603
/* }}} */
36063604

@@ -3639,12 +3637,13 @@ PHP_FUNCTION(iterator_apply)
36393637

36403638
apply_info.count = 0;
36413639
zend_fcall_info_args(&apply_info.fci, apply_info.args);
3642-
if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info) == SUCCESS) {
3643-
RETVAL_LONG(apply_info.count);
3644-
} else {
3645-
RETVAL_FALSE;
3640+
if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info) == FAILURE) {
3641+
zend_fcall_info_args(&apply_info.fci, NULL);
3642+
return;
36463643
}
3644+
36473645
zend_fcall_info_args(&apply_info.fci, NULL);
3646+
RETURN_LONG(apply_info.count);
36483647
}
36493648
/* }}} */
36503649

0 commit comments

Comments
 (0)