Skip to content

Commit e95fa3e

Browse files
committed
Fix a few Iterator signatures
Closes GH-6176
1 parent 9746490 commit e95fa3e

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

ext/spl/spl_iterators.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,17 @@ PHP_METHOD(RecursiveIteratorIterator, getDepth)
684684
PHP_METHOD(RecursiveIteratorIterator, getSubIterator)
685685
{
686686
spl_recursive_it_object *object = Z_SPLRECURSIVE_IT_P(ZEND_THIS);
687-
zend_long level = object->level;
687+
zend_long level;
688+
zend_bool level_is_null = 1;
688689
zval *value;
689690

690-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &level) == FAILURE) {
691+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!", &level, &level_is_null) == FAILURE) {
691692
RETURN_THROWS();
692693
}
693-
if (level < 0 || level > object->level) {
694+
695+
if (level_is_null) {
696+
level = object->level;
697+
} else if (level < 0 || level > object->level) {
694698
RETURN_NULL();
695699
}
696700

@@ -1318,14 +1322,14 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
13181322
}
13191323
case DIT_IteratorIterator: {
13201324
zend_class_entry *ce_cast;
1321-
zend_string *class_name;
1325+
zend_string *class_name = NULL;
13221326

1323-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S", &zobject, ce_inner, &class_name) == FAILURE) {
1327+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S!", &zobject, ce_inner, &class_name) == FAILURE) {
13241328
return NULL;
13251329
}
13261330
ce = Z_OBJCE_P(zobject);
13271331
if (!instanceof_function(ce, zend_ce_iterator)) {
1328-
if (ZEND_NUM_ARGS() > 1) {
1332+
if (class_name) {
13291333
if (!(ce_cast = zend_lookup_class(class_name))
13301334
|| !instanceof_function(ce, ce_cast)
13311335
|| !ce_cast->get_iterator

ext/spl/spl_iterators.stub.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function next() {}
7474
public function getDepth() {}
7575

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

7979
/** @return RecursiveIterator */
8080
public function getInnerIterator() {}
@@ -115,8 +115,7 @@ public function getInnerIterator();
115115

116116
class IteratorIterator implements OuterIterator
117117
{
118-
/** @param Traversable $iterator */
119-
public function __construct($iterator, string $class_name = UNKNOWN) {}
118+
public function __construct(Traversable $iterator, ?string $class_name = null) {}
120119

121120
/** @return Iterator|null */
122121
public function getInnerIterator() {}

ext/spl/spl_iterators_arginfo.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 38fb46070ea48e774343e59de53797969acf4b06 */
2+
* Stub hash: 65bcea1c2313ff50b3e15588e1cdba036995c131 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_EmptyIterator_current, 0, 0, 0)
55
ZEND_END_ARG_INFO()
@@ -51,7 +51,7 @@ ZEND_END_ARG_INFO()
5151
#define arginfo_class_RecursiveIteratorIterator_getDepth arginfo_class_EmptyIterator_current
5252

5353
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveIteratorIterator_getSubIterator, 0, 0, 0)
54-
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
54+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, level, IS_LONG, 1, "null")
5555
ZEND_END_ARG_INFO()
5656

5757
#define arginfo_class_RecursiveIteratorIterator_getInnerIterator arginfo_class_EmptyIterator_current
@@ -79,8 +79,8 @@ ZEND_END_ARG_INFO()
7979
#define arginfo_class_OuterIterator_getInnerIterator arginfo_class_EmptyIterator_current
8080

8181
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IteratorIterator___construct, 0, 0, 1)
82-
ZEND_ARG_INFO(0, iterator)
83-
ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0)
82+
ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0)
83+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, class_name, IS_STRING, 1, "null")
8484
ZEND_END_ARG_INFO()
8585

8686
#define arginfo_class_IteratorIterator_getInnerIterator arginfo_class_EmptyIterator_current

0 commit comments

Comments
 (0)