]> granicus.if.org Git - php/commitdiff
Fix #48667 (Implementing Iterator and IteratorAggregate is now restricted in both...
authorEtienne Kneuss <colder@php.net>
Mon, 1 Feb 2010 13:45:57 +0000 (13:45 +0000)
committerEtienne Kneuss <colder@php.net>
Mon, 1 Feb 2010 13:45:57 +0000 (13:45 +0000)
NEWS
Zend/tests/bug48667_1.phpt [new file with mode: 0644]
Zend/tests/bug48667_2.phpt [new file with mode: 0644]
Zend/zend_interfaces.c

diff --git a/NEWS b/NEWS
index d2a9ca2895094751ce95b77bfb354aded899e907..d63610967c8f57d9a503b1e3f9ae961d2a2f1d28 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -66,6 +66,7 @@ PHP                                                                        NEWS
 - Fixed bug #49851 (http wrapper breaks on 1024 char long headers). (Ilia)
 - Fixed bug #49600 (imageTTFText text shifted right). (Takeshi Abe)
 - Fixed bug #49463 (setAttributeNS fails setting default namespace). (Rob)
+- Fixed bug #48667 (Implementing Iterator and IteratorAggregate). (Etienne)
 - Fixed bug #48590 (SoapClient does not honor max_redirects). (Sriram)
 - Fixed bug #48190 (Content-type parameter "boundary" is not case-insensitive
   in HTTP uploads). (Ilia)
diff --git a/Zend/tests/bug48667_1.phpt b/Zend/tests/bug48667_1.phpt
new file mode 100644 (file)
index 0000000..df98aed
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #48667 (Implementing both iterator and iteratoraggregate)
+--FILE--
+<?php
+
+abstract class A implements Iterator, IteratorAggregate { }
+
+?>
+--EXPECTF--
+Fatal error: Class A cannot implement both IteratorAggregate and Iterator at the same time. in %s on line %d
diff --git a/Zend/tests/bug48667_2.phpt b/Zend/tests/bug48667_2.phpt
new file mode 100644 (file)
index 0000000..6bc707e
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Bug #48667 (Implementing both iterator and iteratoraggregate)
+--FILE--
+<?php
+
+abstract class A implements IteratorAggregate, Iterator { }
+
+?>
+--EXPECTF--
+Fatal error: Class A cannot implement both Iterator and IteratorAggregate at the same time. in %s on line %d
index 3e6ba247a07873c44662712b1b6ee1a5c4305ff1..3a4e2f3e4f718113801fbcdd9346a542481193a2 100755 (executable)
@@ -344,6 +344,10 @@ static int zend_implement_aggregate(zend_class_entry *interface, zend_class_entr
                        if (class_type->num_interfaces) {
                                for (i = 0; i < class_type->num_interfaces; i++) {
                                        if (class_type->interfaces[i] == zend_ce_iterator) {
+                                               zend_error(E_ERROR, "Class %s cannot implement both %s and %s at the same time.",
+                                                                       class_type->name,
+                                                                       interface->name,
+                                                                       zend_ce_iterator->name);
                                                return FAILURE;
                                        }
                                        if (class_type->interfaces[i] == zend_ce_traversable) {
@@ -369,8 +373,14 @@ static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry
                if (class_type->type == ZEND_INTERNAL_CLASS) {
                        /* inheritance ensures the class has the necessary userland methods */
                        return SUCCESS;
-               } else if (class_type->get_iterator != zend_user_it_get_new_iterator) {
+               } else {
                        /* c-level get_iterator cannot be changed */
+                       if (class_type->get_iterator == zend_user_it_get_new_iterator) {
+                               zend_error(E_ERROR, "Class %s cannot implement both %s and %s at the same time.",
+                                                       class_type->name,
+                                                       interface->name,
+                                                       zend_ce_aggregate->name);
+                       }
                        return FAILURE;
                }
        }