Fix a few Iterator signatures
authorMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 21 Sep 2020 12:47:54 +0000 (14:47 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Mon, 21 Sep 2020 14:03:09 +0000 (16:03 +0200)
Closes GH-6176

ext/spl/spl_iterators.c
ext/spl/spl_iterators.stub.php
ext/spl/spl_iterators_arginfo.h

index 731f7f7b6e866ddc35e83a5ee2f5c3d15bd93acb..4735a257a89e7e6090c973d476150372df41caf9 100644 (file)
@@ -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();
        }
 
@@ -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
index ef2615d2ac8c42b599ab47ff91c0a764fc24da44..4d99e60df451bf4e0d1c34916137dd50fa92eb9f 100644 (file)
@@ -74,7 +74,7 @@ class RecursiveIteratorIterator implements OuterIterator
     public function getDepth() {}
 
     /** @return RecursiveIterator|null */
-    public function getSubIterator(int $level = UNKNOWN) {}
+    public function getSubIterator(?int $level = null) {}
 
     /** @return RecursiveIterator */
     public function getInnerIterator() {}
@@ -115,8 +115,7 @@ interface OuterIterator extends Iterator
 
 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() {}
index f8d000e279aa1c480424df20d64a7e37af7558f9..7563521b46c84904b73acdecdad4006a48c0f81d 100644 (file)
@@ -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()
@@ -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
@@ -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