From: Felipe Pena Date: Thu, 3 Dec 2009 12:34:50 +0000 (+0000) Subject: - Fixed bug #49472 (Constants defined in Interfaces can be overridden) X-Git-Tag: php-5.3.2RC1~118 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7914d298b411dc57a95049fc38698fa6c1785fe5;p=php - Fixed bug #49472 (Constants defined in Interfaces can be overridden) --- diff --git a/NEWS b/NEWS index 71af175f4e..06ac7d3841 100644 --- a/NEWS +++ b/NEWS @@ -92,6 +92,8 @@ PHP NEWS - Fixed bug #49647 (DOMUserData does not exist). (Rob) - Fixed bug #49521 (PDO fetchObject sets values before calling constructor). (Pierrick) +- Fixed bug #49472 (Constants defined in Interfaces can be overridden). + (Felipe) - Fixed bug #49244 (Floating point NaN cause garbage characters). (Sjoerd) - Fixed bug #49224 (Compile error due to old DNS functions on AIX systems). (Scott) diff --git a/Zend/tests/bug49472.phpt b/Zend/tests/bug49472.phpt new file mode 100644 index 0000000000..1803d1848c --- /dev/null +++ b/Zend/tests/bug49472.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #49472 (Constants defined in Interfaces can be overridden) +--FILE-- + +--EXPECTF-- +Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d diff --git a/Zend/tests/errmsg_025.phpt b/Zend/tests/errmsg_025.phpt index d853f73428..014b409479 100644 --- a/Zend/tests/errmsg_025.phpt +++ b/Zend/tests/errmsg_025.phpt @@ -16,5 +16,5 @@ class test implements test1, test2 { echo "Done\n"; ?> ---EXPECTF-- -Fatal error: Cannot inherit previously-inherited constant FOO from interface test2 in %s on line %d +--EXPECTF-- +Fatal error: Cannot inherit previously-inherited or override constant FOO from interface test2 in %s on line %d diff --git a/Zend/tests/inter_01.phpt b/Zend/tests/inter_01.phpt index db2e86d206..c73397c91a 100644 --- a/Zend/tests/inter_01.phpt +++ b/Zend/tests/inter_01.phpt @@ -15,4 +15,4 @@ class foobar implements foo { } ?> --EXPECTF-- -Fatal error: Cannot inherit previously-inherited constant foo from interface foo in %s on line %d +Fatal error: Cannot inherit previously-inherited or override constant foo from interface foo in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 080c6aac71..e536f61a10 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2876,8 +2876,8 @@ static zend_bool do_inherit_constant_check(HashTable *child_constants_table, con zval **old_constant; if (zend_hash_quick_find(child_constants_table, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void**)&old_constant) == SUCCESS) { - if (*old_constant != *parent_constant) { - zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited constant %s from interface %s", hash_key->arKey, iface->name); + if (*old_constant != *parent_constant) { + zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %s from interface %s", hash_key->arKey, iface->name); } return 0; } @@ -2885,6 +2885,16 @@ static zend_bool do_inherit_constant_check(HashTable *child_constants_table, con } /* }}} */ +static int do_interface_constant_check(zval **val TSRMLS_DC, int num_args, va_list args, const zend_hash_key *key) /* {{{ */ +{ + zend_class_entry **iface = va_arg(args, zend_class_entry**); + + do_inherit_constant_check(&(*iface)->constants_table, (const zval **) val, key, *iface); + + return ZEND_HASH_APPLY_KEEP; +} +/* }}} */ + ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC) /* {{{ */ { zend_uint i, ignore = 0; @@ -2903,7 +2913,10 @@ ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry } } } - if (!ignore) { + if (ignore) { + /* Check for attempt to redeclare interface constants */ + zend_hash_apply_with_arguments(&ce->constants_table TSRMLS_CC, (apply_func_args_t) do_interface_constant_check, 1, &iface); + } else { if (ce->num_interfaces >= current_iface_num) { if (ce->type == ZEND_INTERNAL_CLASS) { ce->interfaces = (zend_class_entry **) realloc(ce->interfaces, sizeof(zend_class_entry *) * (++current_iface_num));