diff options
author | Marcus Boerger <helly@php.net> | 2005-09-18 17:15:04 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2005-09-18 17:15:04 +0000 |
commit | 7d918fae4c3ab0102258b7e76059c00151a83b3c (patch) | |
tree | 0c964b2db396f93105145e2d92cbe94ed3758c44 | |
parent | 7e762989e700d4adf72867cc10c99195a4681950 (diff) | |
download | php-git-7d918fae4c3ab0102258b7e76059c00151a83b3c.tar.gz |
- Synch naming/move changes with HEAD
- Update tests/docu
# New functionality in CachingIterator/RecursiveIteratorIterator not MFHed
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | ext/spl/examples/directorygraphiterator.inc | 2 | ||||
-rw-r--r-- | ext/spl/examples/directorytreeiterator.inc | 2 | ||||
-rwxr-xr-x | ext/spl/internal/recursivearrayiterator.inc (renamed from ext/spl/examples/recursivearrayiterator.inc) | 2 | ||||
-rwxr-xr-x | ext/spl/internal/recursivecachingiterator.inc (renamed from ext/spl/internal/cachingrecursiveiterator.inc) | 35 | ||||
-rwxr-xr-x | ext/spl/php_spl.c | 3 | ||||
-rwxr-xr-x | ext/spl/spl.php | 2 | ||||
-rwxr-xr-x | ext/spl/spl_array.c | 317 | ||||
-rwxr-xr-x | ext/spl/spl_array.h | 1 | ||||
-rwxr-xr-x | ext/spl/spl_iterators.c | 38 | ||||
-rwxr-xr-x | ext/spl/spl_iterators.h | 4 | ||||
-rwxr-xr-x | ext/spl/tests/array_009.phpt | 15 | ||||
-rwxr-xr-x | ext/spl/tests/bug31926.phpt | 11 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_014.phpt | 45 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_015.phpt | 13 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_016.phpt | 13 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_021.phpt | 41 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_022.phpt | 17 | ||||
-rwxr-xr-x | ext/spl/tests/iterator_023.phpt | 21 |
19 files changed, 315 insertions, 272 deletions
@@ -7,9 +7,12 @@ PHP NEWS classes. (Dmitry, Michael Wallner) - Added "new_link" parameter to mssql_connect(). Bug #34369. (Frank) - Improved SPL extension. (Marcus) - . Added RecursiveFilterIterator + . Moved RecursiveArrayIterator from examples into extension + . Moved RecursiveFilterIterator from examples into extension . Added SplObjectStorage . Made all SPL constants class constants + . Renamed CachingRecursiveIterator to RecursiveCachingIteraotr to follow + Recursive<*>Iterator naming scheme. - Upgraded bundled SQLite library for PDO:SQLite to 3.2.5 (Ilia) - Upgraded SQLite 2 library in ext/sqlite to 2.8.16 (Ilia) - Upgraded PCRE library to version 6.2. (Andrei) diff --git a/ext/spl/examples/directorygraphiterator.inc b/ext/spl/examples/directorygraphiterator.inc index 2c417a50b0..0ba96085b3 100644 --- a/ext/spl/examples/directorygraphiterator.inc +++ b/ext/spl/examples/directorygraphiterator.inc @@ -18,7 +18,7 @@ class DirectoryGraphIterator extends DirectoryTreeIterator { function __construct($path) { - RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1); + RecursiveIteratorIterator::__construct(new RecursiveCachingIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1); } } diff --git a/ext/spl/examples/directorytreeiterator.inc b/ext/spl/examples/directorytreeiterator.inc index ccf8b0f282..1966ce48d8 100644 --- a/ext/spl/examples/directorytreeiterator.inc +++ b/ext/spl/examples/directorytreeiterator.inc @@ -21,7 +21,7 @@ class DirectoryTreeIterator extends RecursiveIteratorIterator */ function __construct($path) { - parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1); + parent::__construct(new RecursiveCachingIterator(new RecursiveDirectoryIterator($path), CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD), 1); } /** @return the current element prefixed with ASCII graphics diff --git a/ext/spl/examples/recursivearrayiterator.inc b/ext/spl/internal/recursivearrayiterator.inc index 305e54cad9..1b4497afd8 100755 --- a/ext/spl/examples/recursivearrayiterator.inc +++ b/ext/spl/internal/recursivearrayiterator.inc @@ -9,7 +9,7 @@ * SPL - Standard PHP Library */ -/** @ingroup Examples +/** @ingroup SPL * @brief A recursive array iterator * @author Marcus Boerger * @version 1.0 diff --git a/ext/spl/internal/cachingrecursiveiterator.inc b/ext/spl/internal/recursivecachingiterator.inc index 5f60d76d5b..9b6ab7ab53 100755 --- a/ext/spl/internal/cachingrecursiveiterator.inc +++ b/ext/spl/internal/recursivecachingiterator.inc @@ -1,8 +1,8 @@ <?php -/** @file cachingrecursiveiterator.inc +/** @file recursivecachingiterator.inc * @ingroup SPL - * @brief class CachingRecursiveIterator + * @brief class RecursiveCachingIterator * @author Marcus Boerger * @date 2003 - 2005 * @@ -12,12 +12,12 @@ /** * @brief Cached recursive iteration over another Iterator * @author Marcus Boerger - * @version 1.1 - * @since PHP 5.0 + * @version 1.2 + * @since PHP 5.1 * * @see CachingIterator */ -class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator +class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator { private $hasChildren; private $getChildren; @@ -48,25 +48,34 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera */ function next() { - if ($this->hasChildren = $this->it->hasChildren()) { - try { - //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->flags); - // workaround memleaks... + if ($this->hasChildren = $this->it->hasChildren()) + { + try + { $child = $this->it->getChildren(); - $this->getChildren = new CachingRecursiveIterator($child, $this->flags); + if (!$this->ref) + { + $this->ref = new ReflectionClass($this); + } + $this->getChildren = $ref->newInstance($child, $this->flags); } - catch(Exception $e) { - if (!$this->flags & self::CATCH_GET_CHILD) { + catch(Exception $e) + { + if (!$this->flags & self::CATCH_GET_CHILD) + { throw $e; } $this->hasChildren = false; $this->getChildren = NULL; } - } else { + } else + { $this->getChildren = NULL; } parent::next(); } + + private $ref; /** @return whether the current element has children * @note The check whether the Iterator for the children can be created was diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 28626bcd18..3c5f4e5330 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -156,7 +156,6 @@ PHP_FUNCTION(class_implements) SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(CachingRecursiveIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \ @@ -175,6 +174,8 @@ PHP_FUNCTION(class_implements) SPL_ADD_CLASS(OverflowException, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(RangeException, z_list, sub, allow, ce_flags); \ + SPL_ADD_CLASS(RecursiveArrayIterator, z_list, sub, allow, ce_flags); \ + SPL_ADD_CLASS(RecursiveCachingIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(RecursiveFilterIterator, z_list, sub, allow, ce_flags); \ SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \ diff --git a/ext/spl/spl.php b/ext/spl/spl.php index 17c5f6f7f8..1f4735b3f6 100755 --- a/ext/spl/spl.php +++ b/ext/spl/spl.php @@ -40,7 +40,7 @@ * - interface SeekableIterator implements Iterator * - class LimitIterator implements OuterIterator * - class CachingIterator implements OuterIterator - * - class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator + * - class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator * - class IteratorIterator implements OuterIterator * - class NoRewindIterator implements OuterIterator * - class EmptyIterator implements Iterator diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index a1d40b62df..e62b2ad10f 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -35,119 +35,22 @@ #include "spl_array.h" #include "spl_exceptions.h" -SPL_METHOD(Array, __construct); -SPL_METHOD(Array, getIterator); -SPL_METHOD(Array, rewind); -SPL_METHOD(Array, current); -SPL_METHOD(Array, key); -SPL_METHOD(Array, next); -SPL_METHOD(Array, valid); -SPL_METHOD(Array, offsetExists); -SPL_METHOD(Array, offsetGet); -SPL_METHOD(Array, offsetSet); -SPL_METHOD(Array, offsetUnset); -SPL_METHOD(Array, append); -SPL_METHOD(Array, getArrayCopy); -SPL_METHOD(Array, exchangeArray); -SPL_METHOD(Array, seek); -SPL_METHOD(Array, count); -SPL_METHOD(Array, getFlags); -SPL_METHOD(Array, setFlags); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array___construct, 0) - ZEND_ARG_INFO(0, array) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetGet, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetSet, 0, 0, 2) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, newval) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_append, 0) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_seek, 0) - ZEND_ARG_INFO(0, position) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_exchangeArray, 0) - ZEND_ARG_INFO(0, array) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_setFlags, 0) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_ArrayObject[] = { - SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetExists, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetGet, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetSet, arginfo_array_offsetSet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetUnset, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, append, arginfo_array_append, ZEND_ACC_PUBLIC) - SPL_ME(Array, getArrayCopy, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, count, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, setFlags, arginfo_array_setFlags, ZEND_ACC_PUBLIC) - /* ArrayObject specific */ - SPL_ME(Array, getIterator, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, exchangeArray, arginfo_array_exchangeArray, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_funcs_ArrayIterator[] = { - SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetExists, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetGet, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetSet, arginfo_array_offsetSet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetUnset, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, append, arginfo_array_append, ZEND_ACC_PUBLIC) - SPL_ME(Array, getArrayCopy, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, count, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, setFlags, arginfo_array_setFlags, ZEND_ACC_PUBLIC) - /* ArrayIterator specific */ - SPL_ME(Array, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, seek, arginfo_array_seek, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_funcs_Countable[] = { - SPL_ABSTRACT_ME(Countable, count, NULL) - {NULL, NULL, NULL} -}; - zend_object_handlers spl_handler_ArrayObject; PHPAPI zend_class_entry *spl_ce_ArrayObject; zend_object_handlers spl_handler_ArrayIterator; PHPAPI zend_class_entry *spl_ce_ArrayIterator; +PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator; PHPAPI zend_class_entry *spl_ce_Countable; -#define SPL_ARRAY_STD_PROP_LIST 0x00000001 -#define SPL_ARRAY_ARRAY_AS_PROPS 0x00000002 -#define SPL_ARRAY_IS_REF 0x01000000 -#define SPL_ARRAY_IS_SELF 0x02000000 -#define SPL_ARRAY_USE_OTHER 0x04000000 -#define SPL_ARRAY_INT_MASK 0xFF000000 -#define SPL_ARRAY_CLONE_MASK 0x03000003 +#define SPL_ARRAY_STD_PROP_LIST 0x00000001 +#define SPL_ARRAY_ARRAY_AS_PROPS 0x00000002 +#define SPL_ARRAY_IS_REF 0x01000000 +#define SPL_ARRAY_IS_SELF 0x02000000 +#define SPL_ARRAY_USE_OTHER 0x04000000 +#define SPL_ARRAY_INT_MASK 0xFF000000 +#define SPL_ARRAY_CLONE_MASK 0x03000007 typedef struct _spl_array_object { zend_object std; @@ -160,6 +63,7 @@ typedef struct _spl_array_object { zend_function * fptr_offset_set; zend_function * fptr_offset_has; zend_function * fptr_offset_del; + zend_class_entry* ce_get_iterator; } spl_array_object; static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int check_std_props TSRMLS_DC) { @@ -275,6 +179,7 @@ static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, s intern->fptr_offset_del = NULL; } } + intern->ce_get_iterator = spl_ce_ArrayIterator; zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); return retval; } @@ -543,7 +448,7 @@ SPL_METHOD(Array, offsetGet) Sets the value at the specified $index to $newval. */ SPL_METHOD(Array, offsetSet) { - zval *index, *value = NULL; + zval *index, *value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &index, &value) == FAILURE) { return; } @@ -855,7 +760,7 @@ zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object } /* }}} */ -/* {{{ proto void ArrayObject::__construct(array|object ar = array()) +/* {{{ proto void ArrayObject::__construct(array|object ar = array() [, int flags = 0 [, string iterator_class = "ArrayIterator"]]) proto void ArrayIterator::__construct(array|object ar = array() [, int flags = 0]) Cronstructs a new array iterator from a path. */ SPL_METHOD(Array, __construct) @@ -864,6 +769,9 @@ SPL_METHOD(Array, __construct) spl_array_object *intern; zval *array; long ar_flags = 0; + char *class_name; + int class_name_len; + zend_class_entry ** pce_get_iterator; if (ZEND_NUM_ARGS() == 0) { return; /* nothing to do */ @@ -872,11 +780,20 @@ SPL_METHOD(Array, __construct) intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &ar_flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ls", &array, &ar_flags, &class_name, &class_name_len) == FAILURE) { php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); return; } + if (ZEND_NUM_ARGS() > 2) { + if (zend_lookup_class(class_name, class_name_len, &pce_get_iterator TSRMLS_CC) == FAILURE) { + zend_throw_exception(spl_ce_InvalidArgumentException, "A class that implements Iterator must be specified", 0 TSRMLS_CC); + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + return; + } + intern->ce_get_iterator = *pce_get_iterator; + } + ar_flags &= ~SPL_ARRAY_INT_MASK; if (Z_TYPE_P(array) == IS_OBJECT && (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject || Z_OBJ_HT_P(array) == &spl_handler_ArrayIterator)) { @@ -911,6 +828,41 @@ SPL_METHOD(Array, __construct) } /* }}} */ +/* {{{ proto void ArrayObject::setIteratorClass(string iterator_class) + Set the class used in getIterator. */ +SPL_METHOD(Array, setIteratorClass) +{ + zval *object = getThis(); + spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); + char *class_name; + int class_name_len; + zend_class_entry ** pce_get_iterator; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name, &class_name_len) == FAILURE) { + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + return; + } + + if (zend_lookup_class(class_name, class_name_len, &pce_get_iterator TSRMLS_CC) == FAILURE) { + zend_throw_exception(spl_ce_InvalidArgumentException, "A class that implements Iterator must be specified", 0 TSRMLS_CC); + php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); + return; + } + intern->ce_get_iterator = *pce_get_iterator; +} +/* }}} */ + +/* {{{ proto string ArrayObject::getIteratorClass() + Get the class used in getIterator. */ +SPL_METHOD(Array, getIteratorClass) +{ + zval *object = getThis(); + spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); + + RETURN_STRING(intern->ce_get_iterator->name, 1); +} +/* }}} */ + /* {{{ proto int ArrayObject::getFlags() Get flags */ SPL_METHOD(Array, getFlags) @@ -994,7 +946,7 @@ SPL_METHOD(Array, getIterator) } return_value->type = IS_OBJECT; - return_value->value.obj = spl_array_object_new_ex(spl_ce_ArrayIterator, &iterator, object TSRMLS_CC); + return_value->value.obj = spl_array_object_new_ex(intern->ce_get_iterator, &iterator, object TSRMLS_CC); return_value->refcount = 1; return_value->is_ref = 1; } @@ -1187,6 +1139,150 @@ SPL_METHOD(Array, valid) } /* }}} */ +/* {{{ proto bool RecursiveArrayIterator::hasChildren() + Check whether current element has children (e.g. is an array) */ +SPL_METHOD(Array, hasChildren) +{ + zval *object = getThis(), **entry; + spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); + HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + + if (!aht) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); + RETURN_FALSE; + } + + if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); + RETURN_FALSE; + } + + if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) { + RETURN_FALSE; + } + + RETURN_BOOL(Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT); +} +/* }}} */ + +/* {{{ proto object RecursiveArrayIterator::getChildren() + Create a sub iterator for the current element (same class as $this) */ +SPL_METHOD(Array, getChildren) +{ + zval *object = getThis(), **entry; + spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); + HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); + + if (!aht) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); + return; + } + + if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(intern TSRMLS_CC) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); + return; + } + + if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) { + return; + } + + spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, *entry TSRMLS_CC); +} +/* }}} */ + +static +ZEND_BEGIN_ARG_INFO(arginfo_array___construct, 0) + ZEND_ARG_INFO(0, array) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetGet, 0, 0, 1) + ZEND_ARG_INFO(0, index) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetSet, 0, 0, 2) + ZEND_ARG_INFO(0, index) + ZEND_ARG_INFO(0, newval) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(arginfo_array_append, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(arginfo_array_seek, 0) + ZEND_ARG_INFO(0, position) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(arginfo_array_exchangeArray, 0) + ZEND_ARG_INFO(0, array) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(arginfo_array_setFlags, 0) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(arginfo_array_setIteratorClass, 0) + ZEND_ARG_INFO(0, iteratorClass) +ZEND_END_ARG_INFO(); + +static zend_function_entry spl_funcs_ArrayObject[] = { + SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetExists, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetGet, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetSet, arginfo_array_offsetSet, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetUnset, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) + SPL_ME(Array, append, arginfo_array_append, ZEND_ACC_PUBLIC) + SPL_ME(Array, getArrayCopy, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, count, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, getFlags, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, setFlags, arginfo_array_setFlags, ZEND_ACC_PUBLIC) + /* ArrayObject specific */ + SPL_ME(Array, getIterator, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, exchangeArray, arginfo_array_exchangeArray, ZEND_ACC_PUBLIC) + SPL_ME(Array, setIteratorClass, arginfo_array_setIteratorClass, ZEND_ACC_PUBLIC) + SPL_ME(Array, getIteratorClass, NULL, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; + +static zend_function_entry spl_funcs_ArrayIterator[] = { + SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetExists, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetGet, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetSet, arginfo_array_offsetSet, ZEND_ACC_PUBLIC) + SPL_ME(Array, offsetUnset, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) + SPL_ME(Array, append, arginfo_array_append, ZEND_ACC_PUBLIC) + SPL_ME(Array, getArrayCopy, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, count, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, getFlags, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, setFlags, arginfo_array_setFlags, ZEND_ACC_PUBLIC) + /* ArrayIterator specific */ + SPL_ME(Array, rewind, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, current, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, key, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, next, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, valid, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, seek, arginfo_array_seek, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; + +static zend_function_entry spl_funcs_RecursiveArrayIterator[] = { + SPL_ME(Array, hasChildren, NULL, ZEND_ACC_PUBLIC) + SPL_ME(Array, getChildren, NULL, ZEND_ACC_PUBLIC) + {NULL, NULL, NULL} +}; + +static zend_function_entry spl_funcs_Countable[] = { + SPL_ABSTRACT_ME(Countable, count, NULL) + {NULL, NULL, NULL} +}; + /* {{{ PHP_MINIT_FUNCTION(spl_array) */ PHP_MINIT_FUNCTION(spl_array) { @@ -1214,6 +1310,9 @@ PHP_MINIT_FUNCTION(spl_array) REGISTER_SPL_IMPLEMENTS(ArrayIterator, SeekableIterator); memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, sizeof(zend_object_handlers)); spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator; + + REGISTER_SPL_SUB_CLASS_EX(RecursiveArrayIterator, ArrayIterator, spl_array_object_new, spl_funcs_RecursiveArrayIterator); + REGISTER_SPL_IMPLEMENTS(RecursiveArrayIterator, RecursiveIterator); REGISTER_SPL_INTERFACE(Countable); diff --git a/ext/spl/spl_array.h b/ext/spl/spl_array.h index 4ee39cb81b..34dedc78dd 100755 --- a/ext/spl/spl_array.h +++ b/ext/spl/spl_array.h @@ -26,6 +26,7 @@ extern PHPAPI zend_class_entry *spl_ce_ArrayObject; extern PHPAPI zend_class_entry *spl_ce_ArrayIterator; +extern PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator; extern PHPAPI zend_class_entry *spl_ce_Countable; PHP_MINIT_FUNCTION(spl_array); diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 4d491a04a5..c89b1eb9c4 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -46,7 +46,7 @@ PHPAPI zend_class_entry *spl_ce_ParentIterator; PHPAPI zend_class_entry *spl_ce_SeekableIterator; PHPAPI zend_class_entry *spl_ce_LimitIterator; PHPAPI zend_class_entry *spl_ce_CachingIterator; -PHPAPI zend_class_entry *spl_ce_CachingRecursiveIterator; +PHPAPI zend_class_entry *spl_ce_RecursiveCachingIterator; PHPAPI zend_class_entry *spl_ce_OuterIterator; PHPAPI zend_class_entry *spl_ce_IteratorIterator; PHPAPI zend_class_entry *spl_ce_NoRewindIterator; @@ -758,7 +758,7 @@ static INLINE spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAME break; } case DIT_CachingIterator: - case DIT_CachingRecursiveIterator: { + case DIT_RecursiveCachingIterator: { long flags = CIT_CALL_TOSTRING; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &zobject, ce_inner, &flags) == FAILURE) { php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); @@ -868,7 +868,7 @@ static INLINE void spl_dual_it_free(spl_dual_it_object *intern TSRMLS_DC) efree(intern->current.str_key); intern->current.str_key = NULL; } - if (intern->dit_type == DIT_CachingIterator || intern->dit_type == DIT_CachingRecursiveIterator) { + if (intern->dit_type == DIT_CachingIterator || intern->dit_type == DIT_RecursiveCachingIterator) { if (intern->u.caching.zstr) { zval_ptr_dtor(&intern->u.caching.zstr); intern->u.caching.zstr = NULL; @@ -1384,7 +1384,7 @@ static INLINE void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC) { if (spl_dual_it_fetch(intern, 1 TSRMLS_CC) == SUCCESS) { intern->u.caching.flags |= CIT_VALID; - if (intern->dit_type == DIT_CachingRecursiveIterator) { + if (intern->dit_type == DIT_RecursiveCachingIterator) { zval *retval, *zchildren, zflags; zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "haschildren", &retval); if (zend_is_true(retval)) { @@ -1397,7 +1397,7 @@ static INLINE void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC) } else { INIT_PZVAL(&zflags); ZVAL_LONG(&zflags, intern->u.caching.flags & CIT_PUBLIC); - spl_instantiate_arg_ex2(spl_ce_CachingRecursiveIterator, &intern->u.caching.zchildren, 1, zchildren, &zflags TSRMLS_CC); + spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &intern->u.caching.zchildren, 1, zchildren, &zflags TSRMLS_CC); zval_ptr_dtor(&zchildren); } } @@ -1546,16 +1546,16 @@ static zend_function_entry spl_funcs_CachingIterator[] = { {NULL, NULL, NULL} }; -/* {{{ proto CachingRecursiveIterator::__construct(RecursiveIterator it [, flags = CIT_CALL_TOSTRING]) +/* {{{ proto RecursiveCachingIterator::__construct(RecursiveIterator it [, flags = CIT_CALL_TOSTRING]) Create an iterator from a RecursiveIterator */ -SPL_METHOD(CachingRecursiveIterator, __construct) +SPL_METHOD(RecursiveCachingIterator, __construct) { - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveIterator, DIT_CachingRecursiveIterator); + spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveIterator, DIT_RecursiveCachingIterator); } /* }}} */ -/* {{{ proto bolean CachingRecursiveIterator::hasChildren() +/* {{{ proto bolean RecursiveCachingIterator::hasChildren() Check whether the current element of the inner iterator has children */ -SPL_METHOD(CachingRecursiveIterator, hasChildren) +SPL_METHOD(RecursiveCachingIterator, hasChildren) { spl_dual_it_object *intern; @@ -1564,9 +1564,9 @@ SPL_METHOD(CachingRecursiveIterator, hasChildren) RETURN_BOOL(intern->u.caching.zchildren); } /* }}} */ -/* {{{ proto CachingRecursiveIterator CachingRecursiveIterator::getChildren() - Return the inner iterator's children as a CachingRecursiveIterator */ -SPL_METHOD(CachingRecursiveIterator, getChildren) +/* {{{ proto RecursiveCachingIterator RecursiveCachingIterator::getChildren() + Return the inner iterator's children as a RecursiveCachingIterator */ +SPL_METHOD(RecursiveCachingIterator, getChildren) { spl_dual_it_object *intern; @@ -1585,10 +1585,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_rec_it___construct, 0, ZEND_RETURN_VALUE, ZEND_ARG_INFO(0, flags) ZEND_END_ARG_INFO(); -static zend_function_entry spl_funcs_CachingRecursiveIterator[] = { - SPL_ME(CachingRecursiveIterator, __construct, arginfo_caching_rec_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(CachingRecursiveIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingRecursiveIterator, getChildren, NULL, ZEND_ACC_PUBLIC) +static zend_function_entry spl_funcs_RecursiveCachingIterator[] = { + SPL_ME(RecursiveCachingIterator, __construct, arginfo_caching_rec_it___construct, ZEND_ACC_PUBLIC) + SPL_ME(RecursiveCachingIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) + SPL_ME(RecursiveCachingIterator, getChildren, NULL, ZEND_ACC_PUBLIC) {NULL, NULL, NULL} }; @@ -2021,8 +2021,8 @@ PHP_MINIT_FUNCTION(spl_iterators) REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CALL_TOSTRING", CIT_CALL_TOSTRING); REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CATCH_GET_CHILD", CIT_CATCH_GET_CHILD); - REGISTER_SPL_SUB_CLASS_EX(CachingRecursiveIterator, CachingIterator, spl_dual_it_new, spl_funcs_CachingRecursiveIterator); - REGISTER_SPL_IMPLEMENTS(CachingRecursiveIterator, RecursiveIterator); + REGISTER_SPL_SUB_CLASS_EX(RecursiveCachingIterator, CachingIterator, spl_dual_it_new, spl_funcs_RecursiveCachingIterator); + REGISTER_SPL_IMPLEMENTS(RecursiveCachingIterator, RecursiveIterator); REGISTER_SPL_STD_CLASS_EX(IteratorIterator, spl_dual_it_new, spl_funcs_IteratorIterator); REGISTER_SPL_ITERATOR(IteratorIterator); diff --git a/ext/spl/spl_iterators.h b/ext/spl/spl_iterators.h index 3e0d0cba11..71e955b5c7 100755 --- a/ext/spl/spl_iterators.h +++ b/ext/spl/spl_iterators.h @@ -38,7 +38,7 @@ extern PHPAPI zend_class_entry *spl_ce_ParentIterator; extern PHPAPI zend_class_entry *spl_ce_SeekableIterator; extern PHPAPI zend_class_entry *spl_ce_LimitIterator; extern PHPAPI zend_class_entry *spl_ce_CachingIterator; -extern PHPAPI zend_class_entry *spl_ce_CachingRecursiveIterator; +extern PHPAPI zend_class_entry *spl_ce_RecursiveCachingIterator; extern PHPAPI zend_class_entry *spl_ce_OuterIterator; extern PHPAPI zend_class_entry *spl_ce_IteratorIterator; extern PHPAPI zend_class_entry *spl_ce_NoRewindIterator; @@ -55,7 +55,7 @@ typedef enum { DIT_Default = 0, DIT_LimitIterator, DIT_CachingIterator, - DIT_CachingRecursiveIterator, + DIT_RecursiveCachingIterator, DIT_IteratorIterator, DIT_NoRewindIterator, DIT_InfiniteIterator, diff --git a/ext/spl/tests/array_009.phpt b/ext/spl/tests/array_009.phpt index fce2b42df2..0431cca77e 100755 --- a/ext/spl/tests/array_009.phpt +++ b/ext/spl/tests/array_009.phpt @@ -5,22 +5,9 @@ SPL: ArrayIterator implementing RecursiveIterator --FILE-- <?php -class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator -{ - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - return new RecursiceArrayIterator($this->current()); - } -} - $array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); -$dir = new RecursiveIteratorIterator(new RecursiceArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY); +$dir = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($dir as $file) { print "$file\n"; diff --git a/ext/spl/tests/bug31926.phpt b/ext/spl/tests/bug31926.phpt index 428039b1cb..2d72df421d 100755 --- a/ext/spl/tests/bug31926.phpt +++ b/ext/spl/tests/bug31926.phpt @@ -5,17 +5,6 @@ Bug #31926 (php in free() error with RecursiveArrayIterator) $array = array(0 => array('world')); -class RecursiveArrayIterator extends ArrayIterator implements -RecursiveIterator { - function hasChildren() { - return (is_array($this->current())); - } - - function getChildren() { - return new self($this->current()); - } -} - $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array)); foreach($it as $key => $val) { var_dump($key, $val); diff --git a/ext/spl/tests/iterator_014.phpt b/ext/spl/tests/iterator_014.phpt index f6e8ce9d01..119fad05fb 100755 --- a/ext/spl/tests/iterator_014.phpt +++ b/ext/spl/tests/iterator_014.phpt @@ -3,19 +3,8 @@ SPL: RecursiveIteratorIterator and beginChildren/endChildren --FILE-- <?php -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator +class MyRecursiveArrayIterator extends RecursiveArrayIterator { - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - echo __METHOD__ . "\n"; - return new RecursiveArrayIterator($this->current()); - } - function valid() { if (!parent::valid()) @@ -28,6 +17,12 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator return true; } } + + function getChildren() + { + echo __METHOD__ . "\n"; + return parent::getChildren(); + } } class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator @@ -73,7 +68,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator } } -foreach(new RecursiveArrayIteratorIterator(new RecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"))) as $k=>$v) +foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"))) as $k=>$v) { echo "$k=>$v\n"; } @@ -87,14 +82,14 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 0=>a RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(1) RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 0=>ba RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(2) RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::current @@ -106,38 +101,38 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 1=>bbb RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(3) RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 0=>bcaa RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(3) -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(1) RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 0=>ca RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 3=>d RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::valid -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false ===DONE=== diff --git a/ext/spl/tests/iterator_015.phpt b/ext/spl/tests/iterator_015.phpt index 3a18efd80f..aa30f79e1f 100755 --- a/ext/spl/tests/iterator_015.phpt +++ b/ext/spl/tests/iterator_015.phpt @@ -3,19 +3,6 @@ SPL: RecursiveIteratorIterator and beginChildren/endChildren --FILE-- <?php -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator -{ - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - return new RecursiveArrayIterator($this->current()); - } -} - class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator { function rewind() diff --git a/ext/spl/tests/iterator_016.phpt b/ext/spl/tests/iterator_016.phpt index 6a811edf29..f231c6eb34 100755 --- a/ext/spl/tests/iterator_016.phpt +++ b/ext/spl/tests/iterator_016.phpt @@ -3,19 +3,6 @@ SPL: RecursiveIteratorIterator and beginChildren/endChildren --FILE-- <?php -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator -{ - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - return new RecursiveArrayIterator($this->current()); - } -} - class Menu extends ArrayObject { function getIterator() diff --git a/ext/spl/tests/iterator_021.phpt b/ext/spl/tests/iterator_021.phpt index 115461d053..4f2395a8e5 100755 --- a/ext/spl/tests/iterator_021.phpt +++ b/ext/spl/tests/iterator_021.phpt @@ -3,19 +3,8 @@ SPL: RecursiveIteratorIterator and hasChildren --FILE-- <?php -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator +class MyRecursiveArrayIterator extends RecursiveArrayIterator { - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - echo __METHOD__ . "\n"; - return new RecursiveArrayIterator($this->current()); - } - function valid() { if (!parent::valid()) @@ -28,6 +17,12 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator return true; } } + + function getChildren() + { + echo __METHOD__ . "\n"; + return parent::getChildren(); + } } class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator @@ -105,7 +100,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator } } -foreach(new RecursiveArrayIteratorIterator(new RecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) +foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) { if (is_array($v)) $v = join('',$v); echo "$k=>$v\n"; @@ -122,7 +117,7 @@ RecursiveArrayIteratorIterator::key 0=>a RecursiveArrayIteratorIterator::next RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(1) RecursiveArrayIteratorIterator::callHasChildren(1) = no/no RecursiveArrayIteratorIterator::valid @@ -131,7 +126,7 @@ RecursiveArrayIteratorIterator::key 0=>ba RecursiveArrayIteratorIterator::next RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(2) RecursiveArrayIteratorIterator::callHasChildren(2) = no/no RecursiveArrayIteratorIterator::valid @@ -145,10 +140,10 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 1=>bbb RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(2) RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes RecursiveArrayIteratorIterator::valid @@ -159,19 +154,19 @@ RecursiveArrayIteratorIterator::next RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -RecursiveArrayIterator::getChildren +MyRecursiveArrayIterator::getChildren RecursiveArrayIteratorIterator::beginChildren(1) RecursiveArrayIteratorIterator::callHasChildren(1) = no/no RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 0=>ca RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) RecursiveArrayIteratorIterator::callHasChildren(0) = no/no RecursiveArrayIteratorIterator::valid @@ -179,7 +174,7 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 3=>d RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::valid -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false ===DONE=== diff --git a/ext/spl/tests/iterator_022.phpt b/ext/spl/tests/iterator_022.phpt index 12bec48b15..8d055313ac 100755 --- a/ext/spl/tests/iterator_022.phpt +++ b/ext/spl/tests/iterator_022.phpt @@ -3,13 +3,8 @@ SPL: RecursiveIteratorIterator and callHasChildren/callGetChildren --FILE-- <?php -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator +class MyRecursiveArrayIterator extends RecursiveArrayIterator { - function hasChildren() - { - return is_array($this->current()); - } - function getChildren() { echo __METHOD__ . "\n"; @@ -102,7 +97,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator return NULL; } echo __METHOD__ . "(ok:{$this->over})\n"; - return new RecursiveArrayIterator($this->current()); + return new MyRecursiveArrayIterator($this->current()); } function beginChildren() @@ -118,7 +113,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator try { - foreach(new RecursiveArrayIteratorIterator(new RecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) + foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) { if (is_array($v)) $v = join('',$v); echo "$k=>$v\n"; @@ -166,7 +161,7 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 1=>bbb RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes RecursiveArrayIteratorIterator::callGetChildren(ok:0) @@ -181,9 +176,9 @@ RecursiveArrayIteratorIterator::next RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes RecursiveArrayIteratorIterator::callGetChildren(skip) diff --git a/ext/spl/tests/iterator_023.phpt b/ext/spl/tests/iterator_023.phpt index 8521fa4674..1b6b4685ec 100755 --- a/ext/spl/tests/iterator_023.phpt +++ b/ext/spl/tests/iterator_023.phpt @@ -3,13 +3,8 @@ SPL: RecursiveIteratorIterator and catch getChildren --FILE-- <?php -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator +class MyRecursiveArrayIterator extends RecursiveArrayIterator { - function hasChildren() - { - return is_array($this->current()); - } - function getChildren() { echo __METHOD__ . "\n"; @@ -102,7 +97,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator throw new Exception("Thrown in callGetChildren()"); } echo __METHOD__ . "(ok:{$this->over})\n"; - return new RecursiveArrayIterator($this->current()); + return new MyRecursiveArrayIterator($this->current()); } function beginChildren() @@ -118,7 +113,7 @@ class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator try { - foreach(new RecursiveArrayIteratorIterator(new RecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) + foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) { if (is_array($v)) $v = join('',$v); echo "$k=>$v\n"; @@ -166,7 +161,7 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 1=>bbb RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes RecursiveArrayIteratorIterator::callGetChildren(ok:0) @@ -181,9 +176,9 @@ RecursiveArrayIteratorIterator::next RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes RecursiveArrayIteratorIterator::valid RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::endChildren(1) RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes RecursiveArrayIteratorIterator::callGetChildren(throw) @@ -192,7 +187,7 @@ RecursiveArrayIteratorIterator::current RecursiveArrayIteratorIterator::key 3=>d RecursiveArrayIteratorIterator::next -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false RecursiveArrayIteratorIterator::valid -RecursiveArrayIterator::valid = false +MyRecursiveArrayIterator::valid = false ===DONE=== |