From: Marcus Boerger Date: Wed, 10 May 2006 00:29:42 +0000 (+0000) Subject: - Fix iterators part and add tests X-Git-Tag: php-5.2.0RC1~627 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=982822be9378aeb63e3eb7b7418616794a6fa4ac;p=php - Fix iterators part and add tests --- diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index d99bcaeff0..22e087ff25 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -1812,7 +1812,6 @@ SPL_METHOD(CachingIterator, offsetSet) spl_dual_it_object *intern; char *arKey; uint nKeyLength; - zend_uchar type; zval *value; intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1821,7 +1820,7 @@ SPL_METHOD(CachingIterator, offsetSet) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); } - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Tz", &arKey, &nKeyLength, &type, &value) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &arKey, &nKeyLength, &value) == FAILURE) { return; } diff --git a/ext/spl/tests/iterator_027.phpt b/ext/spl/tests/iterator_027.phpt new file mode 100755 index 0000000000..633c8fb0ab --- /dev/null +++ b/ext/spl/tests/iterator_027.phpt @@ -0,0 +1,113 @@ +--TEST-- +SPL: CachingIterator::FULL_CACHE +--SKIPIF-- + +--FILE-- +$v) +{ + echo "$k=>$v\n"; +} + +echo "===CHECK===\n"; + +for ($i = 0; $i < 4; $i++) +{ + if (isset($it[$i])) + { + var_dump($i, $it[$i]); + } +} + +$it[2] = 'foo'; +$it[3] = 'bar'; +$it['baz'] = '25'; + +var_dump($it[2]); +var_dump($it[3]); +var_dump($it['baz']); + +unset($it[0]); +unset($it[2]); +unset($it['baz']); + +var_dump(isset($it[0])); // unset +var_dump(isset($it[1])); // still present +var_dump(isset($it[2])); // unset +var_dump(isset($it[3])); // still present +var_dump(isset($it['baz'])); + +echo "===REWIND===\n"; + +$it->rewind(); // cleans and reads first element +var_dump(isset($it[0])); // pre-fetched +var_dump(isset($it[1])); // deleted +var_dump(isset($it[2])); // unset +var_dump(isset($it[3])); // deleted + +?> +===DONE=== + +--EXPECT-- +0=>1 +1=>2 +0=>31 +1=>32 +0=>331 +3=>4 +===CHECK=== +int(0) +int(331) +int(1) +int(32) +int(3) +int(4) +string(3) "foo" +string(3) "bar" +string(2) "25" +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +===REWIND=== +bool(true) +bool(false) +bool(false) +bool(false) +===DONE=== +--UEXPECT-- +0=>1 +1=>2 +0=>31 +1=>32 +0=>331 +3=>4 +===CHECK=== +int(0) +int(331) +int(1) +int(32) +int(3) +int(4) +unicode(3) "foo" +unicode(3) "bar" +unicode(2) "25" +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +===REWIND=== +bool(true) +bool(false) +bool(false) +bool(false) +===DONE=== diff --git a/ext/spl/tests/iterator_029.phpt b/ext/spl/tests/iterator_029.phpt new file mode 100755 index 0000000000..6ca53eff15 --- /dev/null +++ b/ext/spl/tests/iterator_029.phpt @@ -0,0 +1,40 @@ +--TEST-- +SPL: RegExIterator +--SKIPIF-- + +--FILE-- + "abc", "a2b", 22, "a2d" => 7, 42); + +foreach(new RegExIterator(new ArrayIterator($ar), "/2/") as $k => $v) +{ + echo "$k=>$v\n"; +} + +?> +===KEY=== + $v) +{ + echo "$k=>$v\n"; +} + +?> +===DONE=== + +--EXPECT-- +1=>123 +2=>123 +23=>a2b +24=>22 +25=>42 +===KEY=== +2=>123 +22=>abc +23=>a2b +24=>22 +a2d=>7 +25=>42 +===DONE===