]> granicus.if.org Git - php/commitdiff
Allow ReflectionClass::isIterable() to return true for Traversables
authorSara Golemon <pollita@php.net>
Wed, 31 May 2017 21:18:19 +0000 (14:18 -0700)
committerSara Golemon <pollita@php.net>
Wed, 31 May 2017 21:23:57 +0000 (14:23 -0700)
Current behavior is essentially "Is an INTERNAL iterable class".
This change allows isIterable() to return true for userspace classes as well.

ext/reflection/php_reflection.c

index 84f4d66aeb8b05961864ce9c9b20addddfeeb490..19975d29bcd8ee1ae7c40540de039ba5601f4b1f 100644 (file)
@@ -5131,7 +5131,12 @@ ZEND_METHOD(reflection_class, isIterable)
        METHOD_NOTSTATIC(reflection_class_ptr);
        GET_REFLECTION_OBJECT_PTR(ce);
 
-       RETURN_BOOL(ce->get_iterator != NULL);
+       if (ce->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_IMPLICIT_ABSTRACT_CLASS |
+                           ZEND_ACC_TRAIT     | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
+               RETURN_FALSE;
+       }
+
+       RETURN_BOOL(ce->get_iterator || instanceof_function(ce, zend_ce_traversable));
 }
 /* }}} */