Skip to content

Commit b46cf28

Browse files
committed
Use correct constants table
1 parent cd2506f commit b46cf28

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

Zend/tests/bug49472.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ class FooBar extends Foo implements ia {
2323
new FooBar;
2424

2525
?>
26-
--EXPECTF--
27-
Fatal error: Cannot inherit previously-inherited or override constant FooBar::c from interface ia in %s on line %d
26+
===DONE===
27+
--EXPECT--
28+
===DONE===

Zend/zend_inheritance.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,18 +1630,15 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
16301630
/* }}} */
16311631

16321632
static bool do_inherit_constant_check(
1633-
zend_class_entry *ce, HashTable *child_constants_table, zend_class_constant *parent_constant,
1633+
zend_class_entry *ce, zend_class_constant *parent_constant,
16341634
zend_string *name, const zend_class_entry *iface
16351635
) {
1636-
zval *zv = zend_hash_find_ex(child_constants_table, name, 1);
1637-
zend_class_constant *old_constant;
1638-
1636+
zval *zv = zend_hash_find_ex(&ce->constants_table, name, 1);
16391637
if (zv == NULL) {
16401638
return true;
16411639
}
16421640

1643-
old_constant = (zend_class_constant*)Z_PTR_P(zv);
1644-
1641+
zend_class_constant *old_constant = Z_PTR_P(zv);
16451642
if ((ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_FINAL)) {
16461643
zend_error_noreturn(E_COMPILE_ERROR, "%s::%s cannot override final constant %s::%s",
16471644
ZSTR_VAL(old_constant->ce->name), ZSTR_VAL(name), ZSTR_VAL(iface->name), ZSTR_VAL(name)
@@ -1658,7 +1655,7 @@ static bool do_inherit_constant_check(
16581655

16591656
static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
16601657
{
1661-
if (do_inherit_constant_check(ce, &ce->constants_table, c, name, iface)) {
1658+
if (do_inherit_constant_check(ce, c, name, iface)) {
16621659
zend_class_constant *ct;
16631660
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
16641661
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
@@ -1724,8 +1721,8 @@ ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry
17241721
}
17251722
if (ignore) {
17261723
/* Check for attempt to redeclare interface constants */
1727-
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
1728-
do_inherit_constant_check(ce, &iface->constants_table, c, key, iface);
1724+
ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) {
1725+
do_inherit_constant_check(ce, c, key, iface);
17291726
} ZEND_HASH_FOREACH_END();
17301727
} else {
17311728
if (ce->num_interfaces >= current_iface_num) {
@@ -1769,8 +1766,8 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry
17691766
return;
17701767
}
17711768
/* skip duplications */
1772-
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
1773-
do_inherit_constant_check(ce, &iface->constants_table, c, key, iface);
1769+
ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) {
1770+
do_inherit_constant_check(ce, c, key, iface);
17741771
} ZEND_HASH_FOREACH_END();
17751772

17761773
iface = NULL;

tests/classes/interface_constant_inheritance_001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ interface I2 extends I1 {
1212

1313
echo "Done\n";
1414
?>
15-
--EXPECTF--
16-
Fatal error: Cannot inherit previously-inherited or override constant I2::FOO from interface I1 in %s on line 6
15+
--EXPECT--
16+
Done

0 commit comments

Comments
 (0)