From 4bf982eba45d9a215e05c22ff3371e5cfc79f891 Mon Sep 17 00:00:00 2001 From: Antony Dovgal Date: Tue, 6 Jun 2006 10:02:28 +0000 Subject: [PATCH] do not allow to implement the same interface twice add tests --- Zend/tests/objects_012.phpt | 15 +++++++++++++++ Zend/tests/objects_013.phpt | 15 +++++++++++++++ Zend/tests/objects_014.phpt | 15 +++++++++++++++ Zend/zend_compile.c | 11 +++++++++++ 4 files changed, 56 insertions(+) create mode 100644 Zend/tests/objects_012.phpt create mode 100644 Zend/tests/objects_013.phpt create mode 100644 Zend/tests/objects_014.phpt diff --git a/Zend/tests/objects_012.phpt b/Zend/tests/objects_012.phpt new file mode 100644 index 0000000000..95cce3eca9 --- /dev/null +++ b/Zend/tests/objects_012.phpt @@ -0,0 +1,15 @@ +--TEST-- +implementing a class +--FILE-- + +--EXPECTF-- +Fatal error: bar cannot implement foo - it is not an interface in %s on line %d diff --git a/Zend/tests/objects_013.phpt b/Zend/tests/objects_013.phpt new file mode 100644 index 0000000000..cd65bb287a --- /dev/null +++ b/Zend/tests/objects_013.phpt @@ -0,0 +1,15 @@ +--TEST-- +implementing the same interface twice +--FILE-- + +--EXPECTF-- +Fatal error: Cannot implement previously implemented interface foo in %s on line %d diff --git a/Zend/tests/objects_014.phpt b/Zend/tests/objects_014.phpt new file mode 100644 index 0000000000..2dec0c078a --- /dev/null +++ b/Zend/tests/objects_014.phpt @@ -0,0 +1,15 @@ +--TEST-- +extending the same interface twice +--FILE-- + +--EXPECTF-- +Fatal error: Cannot implement previously implemented interface foo in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ad9537322c..ba0facad61 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2382,6 +2382,17 @@ static zend_bool do_inherit_constant_check(HashTable *child_constants_table, zva ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) { + zend_uint i, if_num = ce->num_interfaces, cnt = 0; + + for (i = 0; i < if_num; i++) { + if (ce->interfaces[i] != NULL && ce->interfaces[i]->name_length == iface->name_length && !memcmp(ce->interfaces[i]->name.v, iface->name.v, UG(unicode)?UBYTES(iface->name_length):iface->name_length)) { + cnt++; + if (cnt > 1) { + zend_error(E_COMPILE_ERROR, "Cannot implement previously implemented interface %v", iface->name); + } + } + } + zend_hash_merge_ex(&ce->constants_table, &iface->constants_table, (copy_ctor_func_t) zval_add_ref, sizeof(zval *), (merge_checker_func_t) do_inherit_constant_check, iface); zend_hash_merge_ex(&ce->function_table, &iface->function_table, (copy_ctor_func_t) do_inherit_method, sizeof(zend_function), (merge_checker_func_t) do_inherit_method_check, ce); -- 2.50.1