cvs: ZendEngine2 / zend_compile.c /tests objects_012.phpt objects_013.phpt objects_014.phpt
| From: | Antony Dovgal | Date: | Tue, 06 Jun 2006 10:02:28 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c /tests objects_012.phpt objects_013.phpt objects_014.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-4972@lists.php.net to get a copy of this message | ||
tony2001 Tue Jun 6 10:02:28 2006 UTC
Added files:
/ZendEngine2/tests objects_012.phpt objects_013.phpt
objects_014.phpt
Modified files:
/ZendEngine2 zend_compile.c
Log:
do not allow to implement the same interface twice
add tests
http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_compile.c?r1=1.712&r2=1.713&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.712 ZendEngine2/zend_compile.c:1.713
--- ZendEngine2/zend_compile.c:1.712 Tue May 30 23:10:55 2006
+++ ZendEngine2/zend_compile.c Tue Jun 6 10:02:28 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.712 2006/05/30 23:10:55 helly Exp $ */
+/* $Id: zend_compile.c,v 1.713 2006/06/06 10:02:28 tony2001 Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -2382,6 +2382,17 @@
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);
http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/objects_012.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/objects_012.phpt
+++ ZendEngine2/tests/objects_012.phpt
--TEST--
implementing a class
--FILE--
<?php
class foo {
}
interface bar extends foo {
}
echo "Done\n";
?>
--EXPECTF--
Fatal error: bar cannot implement foo - it is not an interface in %s on line %d
http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/objects_013.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/objects_013.phpt
+++ ZendEngine2/tests/objects_013.phpt
--TEST--
implementing the same interface twice
--FILE--
<?php
interface foo {
}
class bar implements foo, foo {
}
echo "Done\n";
?>
--EXPECTF--
Fatal error: Cannot implement previously implemented interface foo in %s on line %d
http://cvs.php.net/viewcvs.cgi/ZendEngine2/tests/objects_014.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/objects_014.phpt
+++ ZendEngine2/tests/objects_014.phpt
--TEST--
extending the same interface twice
--FILE--
<?php
interface foo {
}
interface bar extends foo, foo {
}
echo "Done\n";
?>
--EXPECTF--
Fatal error: Cannot implement previously implemented interface foo in %s on line %d