From: Pierre Joye Date: Fri, 5 Feb 2010 00:37:07 +0000 (+0000) Subject: - Fix #48667 (Implementing Iterator and IteratorAggregate is now restricted.. X-Git-Tag: php-5.3.2RC2~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca5eda446787f5f52e3dcf5c52ccabc34688d2e4;p=php - Fix #48667 (Implementing Iterator and IteratorAggregate is now restricted.. --- diff --git a/Zend/tests/bug48667_1.phpt b/Zend/tests/bug48667_1.phpt new file mode 100644 index 0000000000..2d94aed2bf --- /dev/null +++ b/Zend/tests/bug48667_1.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #48667 (Implementing both iterator and iteratoraggregate) +--FILE-- + +--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 index 0000000000..57cd5eb8b8 --- /dev/null +++ b/Zend/tests/bug48667_2.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #48667 (Implementing both iterator and iteratoraggregate) +--FILE-- + +--EXPECTF-- +Fatal error: Class A cannot implement both Iterator and IteratorAggregate at the same time in %s on line %d diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 4106c7e2da..517b116318 100755 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -353,6 +353,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) { @@ -378,8 +382,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; } }