--- /dev/null
+--TEST--
+Bug #49472 (Constants defined in Interfaces can be overridden)
+--FILE--
+<?php
+
+interface ia {
+ const c = 'Sea';
+ const y = 2;
+}
+
+class Foo implements ia {
+}
+
+class FooBar extends Foo implements ia {
+ const x = 1;
+ const c = 'Ocean';
+
+ public function show() {
+ return ia::c;
+ }
+}
+
+new FooBar;
+
+?>
+--EXPECTF--
+Fatal error: Cannot inherit previously-inherited or override constant c from interface ia in %s on line %d
if (zend_u_hash_quick_find(child_constants_table, hash_key->type, 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 %R from interface %v", hash_key->type, hash_key->arKey, iface->name);
+ zend_error(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %R from interface %v", hash_key->type, hash_key->arKey, iface->name);
}
return 0;
}
}
/* }}} */
+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;
}
}
}
- 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));