Skip to content

Fix a few Iterator signatures #6176

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions ext/spl/spl_iterators.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,17 @@ PHP_METHOD(RecursiveIteratorIterator, getDepth)
PHP_METHOD(RecursiveIteratorIterator, getSubIterator)
{
spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(ZEND_THIS);
zend_long level = object->level;
zend_long level;
zend_bool level_is_null = 1;
zval *value;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &level) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &level, &level_is_null) == FAILURE) {
RETURN_THROWS();
}
if (level < 0 || level > object->level) {

if (level_is_null) {
level = object->level;
} else if (level < 0 || level > object->level) {
RETURN_NULL();
}

Expand Down Expand Up @@ -1318,14 +1322,14 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
}
case DIT_IteratorIterator: {
zend_class_entry *ce_cast;
zend_string *class_name;
zend_string *class_name = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S", &zobject, ce_inner, &class_name) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S!", &zobject, ce_inner, &class_name) == FAILURE) {
return NULL;
}
ce = Z_OBJCE_P(zobject);
if (!instanceof_function(ce, zend_ce_iterator)) {
if (ZEND_NUM_ARGS() > 1) {
if (class_name) {
if (!(ce_cast = zend_lookup_class(class_name))
|| !instanceof_function(ce, ce_cast)
|| !ce_cast->get_iterator
Expand Down
5 changes: 2 additions & 3 deletions ext/spl/spl_iterators.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function next() {}
public function getDepth() {}

/** @return RecursiveIterator|null */
public function getSubIterator(int $level = UNKNOWN) {}
public function getSubIterator(?int $level = null) {}

/** @return RecursiveIterator */
public function getInnerIterator() {}
Expand Down Expand Up @@ -115,8 +115,7 @@ public function getInnerIterator();

class IteratorIterator implements OuterIterator
{
/** @param Traversable $iterator */
public function __construct($iterator, string $class_name = UNKNOWN) {}
public function __construct(Traversable $iterator, ?string $class_name = null) {}

/** @return Iterator|null */
public function getInnerIterator() {}
Expand Down
8 changes: 4 additions & 4 deletions ext/spl/spl_iterators_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 38fb46070ea48e774343e59de53797969acf4b06 */
* Stub hash: 65bcea1c2313ff50b3e15588e1cdba036995c131 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_EmptyIterator_current, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -51,7 +51,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_RecursiveIteratorIterator_getDepth arginfo_class_EmptyIterator_current

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveIteratorIterator_getSubIterator, 0, 0, 0)
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, level, IS_LONG, 1, "null")
ZEND_END_ARG_INFO()

#define arginfo_class_RecursiveIteratorIterator_getInnerIterator arginfo_class_EmptyIterator_current
Expand Down Expand Up @@ -79,8 +79,8 @@ ZEND_END_ARG_INFO()
#define arginfo_class_OuterIterator_getInnerIterator arginfo_class_EmptyIterator_current

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IteratorIterator___construct, 0, 0, 1)
ZEND_ARG_INFO(0, iterator)
ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, class_name, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()

#define arginfo_class_IteratorIterator_getInnerIterator arginfo_class_EmptyIterator_current
Expand Down