Don't use quiet zpp in RecursiveIteratorIterator ctor

Don't be a special snowflake, generate a standard TypeError here.
This commit is contained in:
Nikita Popov 2020-03-23 14:22:51 +01:00
parent bdb63a3068
commit 816a1fd4af
3 changed files with 36 additions and 37 deletions

View File

@ -486,56 +486,55 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
zend_error_handling error_handling;
zval caching_it, aggregate_retval;
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
switch (rit_type) {
case RIT_RecursiveTreeIterator: {
zval caching_it_flags, *user_caching_it_flags = NULL;
mode = RIT_SELF_FIRST;
flags = RTIT_BYPASS_KEY;
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "o|lzl", &iterator, &flags, &user_caching_it_flags, &mode) == SUCCESS) {
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator, "getiterator", &aggregate_retval);
iterator = &aggregate_retval;
} else {
Z_ADDREF_P(iterator);
}
if (user_caching_it_flags) {
ZVAL_COPY(&caching_it_flags, user_caching_it_flags);
} else {
ZVAL_LONG(&caching_it_flags, CIT_CATCH_GET_CHILD);
}
spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &caching_it, iterator, &caching_it_flags);
zval_ptr_dtor(&caching_it_flags);
zval_ptr_dtor(iterator);
iterator = &caching_it;
} else {
iterator = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|lzl", &iterator, &flags, &user_caching_it_flags, &mode) == FAILURE) {
RETURN_THROWS();
}
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator, "getiterator", &aggregate_retval);
iterator = &aggregate_retval;
} else {
Z_ADDREF_P(iterator);
}
if (user_caching_it_flags) {
ZVAL_COPY(&caching_it_flags, user_caching_it_flags);
} else {
ZVAL_LONG(&caching_it_flags, CIT_CATCH_GET_CHILD);
}
spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &caching_it, iterator, &caching_it_flags);
zval_ptr_dtor(&caching_it_flags);
zval_ptr_dtor(iterator);
iterator = &caching_it;
break;
}
case RIT_RecursiveIteratorIterator:
default: {
mode = RIT_LEAVES_ONLY;
flags = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|ll", &iterator, &mode, &flags) == FAILURE) {
RETURN_THROWS();
}
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "o|ll", &iterator, &mode, &flags) == SUCCESS) {
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator, "getiterator", &aggregate_retval);
iterator = &aggregate_retval;
} else {
Z_ADDREF_P(iterator);
}
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
zend_call_method_with_0_params(Z_OBJ_P(iterator), Z_OBJCE_P(iterator), &Z_OBJCE_P(iterator)->iterator_funcs_ptr->zf_new_iterator, "getiterator", &aggregate_retval);
iterator = &aggregate_retval;
} else {
iterator = NULL;
Z_ADDREF_P(iterator);
}
break;
}
}
if (!iterator || !instanceof_function(Z_OBJCE_P(iterator), spl_ce_RecursiveIterator)) {
if (!instanceof_function(Z_OBJCE_P(iterator), spl_ce_RecursiveIterator)) {
if (iterator) {
zval_ptr_dtor(iterator);
}

View File

@ -10,9 +10,9 @@ class myRecursiveIteratorIterator extends RecursiveIteratorIterator {
try {
$it = new myRecursiveIteratorIterator();
} catch (InvalidArgumentException $e) {
echo 'InvalidArgumentException thrown';
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
InvalidArgumentException thrown
RecursiveIteratorIterator::__construct() expects at least 1 parameter, 0 given

View File

@ -6,9 +6,9 @@ error_reporting=E_ALL&~E_NOTICE
<?php
try {
new RecursiveTreeIterator();
} catch (InvalidArgumentException $e) {
echo "InvalidArgumentException thrown\n";
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
InvalidArgumentException thrown
RecursiveTreeIterator::__construct() expects at least 1 parameter, 0 given