diff options
| author | Etienne Kneuss <colder@php.net> | 2010-02-01 13:45:57 +0000 |
|---|---|---|
| committer | Etienne Kneuss <colder@php.net> | 2010-02-01 13:45:57 +0000 |
| commit | 3c8298066679830bcab34b84a1a0cc0765a1751f (patch) | |
| tree | 62d1ee15b0ecf9dd0eeebad926269b4aff2b6588 | |
| parent | 1b1f5e9064cbbe86ef198b84654fc40225b8df90 (diff) | |
| download | php-git-3c8298066679830bcab34b84a1a0cc0765a1751f.tar.gz | |
Fix #48667 (Implementing Iterator and IteratorAggregate is now restricted in both orders)
| -rw-r--r-- | Zend/tests/bug48667_1.phpt | 10 | ||||
| -rw-r--r-- | Zend/tests/bug48667_2.phpt | 10 | ||||
| -rwxr-xr-x | Zend/zend_interfaces.c | 12 |
3 files changed, 31 insertions, 1 deletions
diff --git a/Zend/tests/bug48667_1.phpt b/Zend/tests/bug48667_1.phpt new file mode 100644 index 0000000000..df98aed349 --- /dev/null +++ b/Zend/tests/bug48667_1.phpt @@ -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 index 0000000000..6bc707eeeb --- /dev/null +++ b/Zend/tests/bug48667_2.phpt @@ -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 diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 6aeb3517d7..101c4e91dc 100755 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -361,6 +361,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 %v cannot implement both %v and %v at the same time.", + class_type->name, + interface->name, + zend_ce_iterator->name); return FAILURE; } if (class_type->interfaces[i] == zend_ce_traversable) { @@ -386,8 +390,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 %v cannot implement both %v and %v at the same time.", + class_type->name, + interface->name, + zend_ce_aggregate->name); + } return FAILURE; } } |
