From f876597452f2eb74c3acd85157818e6b7f60f8fb Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Fri, 26 May 2006 01:40:57 +0000 Subject: [PATCH] - Fix handling of third parameter to iterator_apply() - Add test --- ext/spl/php_spl.c | 2 +- ext/spl/spl_iterators.c | 5 ++- ext/spl/tests/spl_004.phpt | 86 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100755 ext/spl/tests/spl_004.phpt diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 83d386187b..b763c1a3df 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -628,7 +628,7 @@ static ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_apply, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) ZEND_ARG_INFO(0, function) - ZEND_ARG_ARRAY_INFO(0, args, 0) + ZEND_ARG_ARRAY_INFO(0, args, 1) ZEND_END_ARG_INFO(); /* {{{ spl_functions diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 17d4be3eea..f2368133b0 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -2682,8 +2682,9 @@ PHP_FUNCTION(iterator_apply) { spl_iterator_apply_info apply_info; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Of|a", &apply_info.obj, zend_ce_traversable, &apply_info.fci, &apply_info.fcc, &apply_info.args) == FAILURE) { - RETURN_FALSE; + apply_info.args = NULL; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Of|a!", &apply_info.obj, zend_ce_traversable, &apply_info.fci, &apply_info.fcc, &apply_info.args) == FAILURE) { + return; } apply_info.count = 0; diff --git a/ext/spl/tests/spl_004.phpt b/ext/spl/tests/spl_004.phpt new file mode 100755 index 0000000000..60da28042a --- /dev/null +++ b/ext/spl/tests/spl_004.phpt @@ -0,0 +1,86 @@ +--TEST-- +SPL: iterator_apply() +--SKIPIF-- + +--FILE-- +key()); + var_dump($arg->current()); + } + else + { + var_dump($arg); + } + return true; +} + +function test() +{ + static $arg = 0; + var_dump($arg++); + return true; +} + +$it = new RecursiveArrayIterator(array(1, array(21, 22), 3)); + +var_dump(iterator_apply($it, 'test', NULL)); + +echo "===ARGS===\n"; +var_dump(iterator_apply($it, 'test_arg', array($it))); + +echo "===RECURSIVE===\n"; +$it = new RecursiveIteratorIterator($it); +var_dump(iterator_apply($it, 'test')); + +echo "===ERRORS===\n"; +var_dump(iterator_apply($it, 'test', 1)); +var_dump(iterator_apply($it, 'non_existing_functon')); +var_dump(iterator_apply($it, 'non_existing_functon', NULL, 2)); + +?> +===DONE=== + +--EXPECTF-- +int(0) +int(1) +int(2) +int(3) +===ARGS=== +int(0) +int(1) +int(1) +array(2) { + [0]=> + int(21) + [1]=> + int(22) +} +int(2) +int(3) +int(3) +===RECURSIVE=== +int(3) +int(4) +int(5) +int(6) +int(4) +===ERRORS=== +Error: Argument 3 passed to iterator_apply() must be an array, integer given +Error: iterator_apply() expects parameter 3 to be array, integer given +NULL +Error: iterator_apply() expects parameter 2 to be function,%sstring given +NULL +Error: iterator_apply() expects at most 3 parameters, 4 given +NULL +===DONE=== -- 2.40.0