]> granicus.if.org Git - php/commitdiff
Fixed bug RecursiveArrayIterator does not implement Countable
authorNikita Popov <nikic@php.net>
Tue, 19 Jun 2012 15:45:04 +0000 (17:45 +0200)
committerNikita Popov <nikic@php.net>
Tue, 19 Jun 2012 16:32:44 +0000 (18:32 +0200)
ArrayIterator implemented Countable only after it was already inherited by
RecursiveArrayIterator. Thus the interface was missing in RAI.

ext/spl/spl_array.c
ext/spl/tests/bug62262.phpt [new file with mode: 0644]

index 6e9525e5cedd18d588d5b3170993239ea827947d..5bbab907e46bd5fe76251187feb78242685fcb79 100755 (executable)
@@ -2005,6 +2005,7 @@ PHP_MINIT_FUNCTION(spl_array)
        REGISTER_SPL_IMPLEMENTS(ArrayObject, Aggregate);
        REGISTER_SPL_IMPLEMENTS(ArrayObject, ArrayAccess);
        REGISTER_SPL_IMPLEMENTS(ArrayObject, Serializable);
+       REGISTER_SPL_IMPLEMENTS(ArrayObject, Countable);
        spl_ce_ArrayObject->serialize   = spl_array_serialize;
        spl_ce_ArrayObject->unserialize = spl_array_unserialize;
        memcpy(&spl_handler_ArrayObject, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
@@ -2031,6 +2032,7 @@ PHP_MINIT_FUNCTION(spl_array)
        REGISTER_SPL_IMPLEMENTS(ArrayIterator, ArrayAccess);
        REGISTER_SPL_IMPLEMENTS(ArrayIterator, SeekableIterator);
        REGISTER_SPL_IMPLEMENTS(ArrayIterator, Serializable);
+       REGISTER_SPL_IMPLEMENTS(ArrayIterator, Countable);
        spl_ce_ArrayIterator->serialize   = spl_array_serialize;
        spl_ce_ArrayIterator->unserialize = spl_array_unserialize;
        memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, sizeof(zend_object_handlers));
@@ -2040,9 +2042,6 @@ PHP_MINIT_FUNCTION(spl_array)
        REGISTER_SPL_IMPLEMENTS(RecursiveArrayIterator, RecursiveIterator);
        spl_ce_RecursiveArrayIterator->get_iterator = spl_array_get_iterator;
 
-       REGISTER_SPL_IMPLEMENTS(ArrayObject, Countable);
-       REGISTER_SPL_IMPLEMENTS(ArrayIterator, Countable);
-
        REGISTER_SPL_CLASS_CONST_LONG(ArrayObject,   "STD_PROP_LIST",    SPL_ARRAY_STD_PROP_LIST);
        REGISTER_SPL_CLASS_CONST_LONG(ArrayObject,   "ARRAY_AS_PROPS",   SPL_ARRAY_ARRAY_AS_PROPS);
 
diff --git a/ext/spl/tests/bug62262.phpt b/ext/spl/tests/bug62262.phpt
new file mode 100644 (file)
index 0000000..0e006ec
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #62262: RecursiveArrayIterator does not implement Countable
+--FILE--
+<?php
+
+var_dump(new RecursiveArrayIterator(array()) instanceof Countable);
+
+?>
+--EXPECT--
+bool(true)