Skip to content

Commit 816a1fd

Browse files
committed
Don't use quiet zpp in RecursiveIteratorIterator ctor
Don't be a special snowflake, generate a standard TypeError here.
1 parent bdb63a3 commit 816a1fd

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

ext/spl/spl_iterators.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -486,56 +486,55 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
486486
zend_error_handling error_handling;
487487
zval caching_it, aggregate_retval;
488488

489-
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
490-
491489
switch (rit_type) {
492490
case RIT_RecursiveTreeIterator: {
493491
zval caching_it_flags, *user_caching_it_flags = NULL;
494492
mode = RIT_SELF_FIRST;
495493
flags = RTIT_BYPASS_KEY;
496494

497-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "o|lzl", &iterator, &flags, &user_caching_it_flags, &mode) == SUCCESS) {
498-
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
499-
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);
500-
iterator = &aggregate_retval;
501-
} else {
502-
Z_ADDREF_P(iterator);
503-
}
495+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|lzl", &iterator, &flags, &user_caching_it_flags, &mode) == FAILURE) {
496+
RETURN_THROWS();
497+
}
504498

505-
if (user_caching_it_flags) {
506-
ZVAL_COPY(&caching_it_flags, user_caching_it_flags);
507-
} else {
508-
ZVAL_LONG(&caching_it_flags, CIT_CATCH_GET_CHILD);
509-
}
510-
spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &caching_it, iterator, &caching_it_flags);
511-
zval_ptr_dtor(&caching_it_flags);
499+
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
500+
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
501+
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);
502+
iterator = &aggregate_retval;
503+
} else {
504+
Z_ADDREF_P(iterator);
505+
}
512506

513-
zval_ptr_dtor(iterator);
514-
iterator = &caching_it;
507+
if (user_caching_it_flags) {
508+
ZVAL_COPY(&caching_it_flags, user_caching_it_flags);
515509
} else {
516-
iterator = NULL;
510+
ZVAL_LONG(&caching_it_flags, CIT_CATCH_GET_CHILD);
517511
}
512+
spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &caching_it, iterator, &caching_it_flags);
513+
zval_ptr_dtor(&caching_it_flags);
514+
515+
zval_ptr_dtor(iterator);
516+
iterator = &caching_it;
518517
break;
519518
}
520519
case RIT_RecursiveIteratorIterator:
521520
default: {
522521
mode = RIT_LEAVES_ONLY;
523522
flags = 0;
523+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|ll", &iterator, &mode, &flags) == FAILURE) {
524+
RETURN_THROWS();
525+
}
524526

525-
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "o|ll", &iterator, &mode, &flags) == SUCCESS) {
526-
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
527-
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);
528-
iterator = &aggregate_retval;
529-
} else {
530-
Z_ADDREF_P(iterator);
531-
}
527+
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
528+
if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate)) {
529+
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);
530+
iterator = &aggregate_retval;
532531
} else {
533-
iterator = NULL;
532+
Z_ADDREF_P(iterator);
534533
}
535534
break;
536535
}
537536
}
538-
if (!iterator || !instanceof_function(Z_OBJCE_P(iterator), spl_ce_RecursiveIterator)) {
537+
if (!instanceof_function(Z_OBJCE_P(iterator), spl_ce_RecursiveIterator)) {
539538
if (iterator) {
540539
zval_ptr_dtor(iterator);
541540
}

ext/spl/tests/iterator_062.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class myRecursiveIteratorIterator extends RecursiveIteratorIterator {
1010

1111
try {
1212
$it = new myRecursiveIteratorIterator();
13-
} catch (InvalidArgumentException $e) {
14-
echo 'InvalidArgumentException thrown';
13+
} catch (TypeError $e) {
14+
echo $e->getMessage(), "\n";
1515
}
1616
?>
1717
--EXPECT--
18-
InvalidArgumentException thrown
18+
RecursiveIteratorIterator::__construct() expects at least 1 parameter, 0 given

ext/spl/tests/recursive_tree_iterator_002.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ error_reporting=E_ALL&~E_NOTICE
66
<?php
77
try {
88
new RecursiveTreeIterator();
9-
} catch (InvalidArgumentException $e) {
10-
echo "InvalidArgumentException thrown\n";
9+
} catch (TypeError $e) {
10+
echo $e->getMessage(), "\n";
1111
}
1212
?>
1313
--EXPECT--
14-
InvalidArgumentException thrown
14+
RecursiveTreeIterator::__construct() expects at least 1 parameter, 0 given

0 commit comments

Comments
 (0)