Skip to content

Fixes Bug #71412 Incorrect ArrayIterator __construct signature #2566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static zend_always_inline uint32_t *spl_array_get_pos_ptr(HashTable *ht, spl_arr
static void spl_array_object_free_storage(zend_object *object)
{
spl_array_object *intern = spl_array_from_obj(object);

if (intern->ht_iter != (uint32_t) -1) {
zend_hash_iterator_del(intern->ht_iter);
}
Expand Down Expand Up @@ -1192,8 +1192,7 @@ zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object,
/* }}} */

/* {{{ 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]])
Constructs a new array iterator from a path. */
Constructs a new array object from an array or object. */
SPL_METHOD(Array, __construct)
{
zval *object = getThis();
Expand Down Expand Up @@ -1222,6 +1221,31 @@ SPL_METHOD(Array, __construct)
}
/* }}} */

/* {{{ proto void ArrayIterator::__construct([array|object ar = array() [, int flags = 0]])
Constructs a new array iterator from an array or object. */
SPL_METHOD(ArrayIterator, __construct)
{
zval *object = getThis();
spl_array_object *intern;
zval *array;
zend_long ar_flags = 0;

if (ZEND_NUM_ARGS() == 0) {
return; /* nothing to do */
}

if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z|l", &array, &ar_flags) == FAILURE) {
return;
}

intern = Z_SPLARRAY_P(object);

ar_flags &= ~SPL_ARRAY_INT_MASK;

spl_array_set_array(object, intern, array, ar_flags, ZEND_NUM_ARGS() == 1);
}
/* }}} */

/* {{{ proto void ArrayObject::setIteratorClass(string iterator_class)
Set the class used in getIterator. */
SPL_METHOD(Array, setIteratorClass)
Expand Down Expand Up @@ -1839,6 +1863,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_array___construct, 0, 0, 0)
ZEND_ARG_INFO(0, iterator_class)
ZEND_END_ARG_INFO()

/* ArrayIterator::__construct and ArrayObject::__construct have different signatures */
ZEND_BEGIN_ARG_INFO_EX(arginfo_array_iterator___construct, 0, 0, 0)
ZEND_ARG_INFO(0, array)
ZEND_ARG_INFO(0, ar_flags)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetGet, 0, 0, 1)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -1907,7 +1937,7 @@ static const zend_function_entry spl_funcs_ArrayObject[] = {
};

static const zend_function_entry spl_funcs_ArrayIterator[] = {
SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC)
SPL_ME(ArrayIterator, __construct, arginfo_array_iterator___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)
Expand Down