Skip to content

Commit 0fbf3fe

Browse files
committed
Improve error message
1 parent b46cf28 commit 0fbf3fe

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

Zend/tests/constants/final_constants/final_const11.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class C2 extends C implements I
1919

2020
?>
2121
--EXPECTF--
22-
Fatal error: Cannot inherit previously-inherited or override constant C2::C from interface I in %s on line %d
22+
Fatal error: Class C2 inherits both C::C and I::C, which is ambiguous in %s on line %d

Zend/tests/constants/final_constants/final_const12.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ interface I3 extends I1, I2
1919

2020
?>
2121
--EXPECTF--
22-
Fatal error: Cannot inherit previously-inherited or override constant I3::C from interface I2 in %s on line %d
22+
Fatal error: Class I3 inherits both I1::C and I2::C, which is ambiguous in %s on line %d

Zend/tests/constants/final_constants/final_const8.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class C implements I1, I2
1919

2020
?>
2121
--EXPECTF--
22-
Fatal error: Cannot inherit previously-inherited or override constant C::C from interface I2 in %s on line %d
22+
Fatal error: Class C inherits both I1::C and I2::C, which is ambiguous in %s on line %d

Zend/tests/errmsg_025.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ class test implements test1, test2 {
1717
echo "Done\n";
1818
?>
1919
--EXPECTF--
20-
Fatal error: Cannot inherit previously-inherited or override constant test::FOO from interface test2 in %s on line %d
20+
Fatal error: Class test inherits both test1::FOO and test2::FOO, which is ambiguous in %s on line %d

Zend/zend_inheritance.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,8 +1630,7 @@ 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, zend_class_constant *parent_constant,
1634-
zend_string *name, const zend_class_entry *iface
1633+
zend_class_entry *ce, zend_class_constant *parent_constant, zend_string *name
16351634
) {
16361635
zval *zv = zend_hash_find_ex(&ce->constants_table, name, 1);
16371636
if (zv == NULL) {
@@ -1641,12 +1640,17 @@ static bool do_inherit_constant_check(
16411640
zend_class_constant *old_constant = Z_PTR_P(zv);
16421641
if ((ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_FINAL)) {
16431642
zend_error_noreturn(E_COMPILE_ERROR, "%s::%s cannot override final constant %s::%s",
1644-
ZSTR_VAL(old_constant->ce->name), ZSTR_VAL(name), ZSTR_VAL(iface->name), ZSTR_VAL(name)
1643+
ZSTR_VAL(old_constant->ce->name), ZSTR_VAL(name),
1644+
ZSTR_VAL(parent_constant->ce->name), ZSTR_VAL(name)
16451645
);
16461646
}
16471647

16481648
if (old_constant->ce != parent_constant->ce && old_constant->ce != ce) {
1649-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot inherit previously-inherited or override constant %s::%s from interface %s", ZSTR_VAL(ce->name), ZSTR_VAL(name), ZSTR_VAL(iface->name));
1649+
zend_error_noreturn(E_COMPILE_ERROR,
1650+
"Class %s inherits both %s::%s and %s::%s, which is ambiguous",
1651+
ZSTR_VAL(ce->name),
1652+
ZSTR_VAL(old_constant->ce->name), ZSTR_VAL(name),
1653+
ZSTR_VAL(parent_constant->ce->name), ZSTR_VAL(name));
16501654
}
16511655

16521656
return false;
@@ -1655,7 +1659,7 @@ static bool do_inherit_constant_check(
16551659

16561660
static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
16571661
{
1658-
if (do_inherit_constant_check(ce, c, name, iface)) {
1662+
if (do_inherit_constant_check(ce, c, name)) {
16591663
zend_class_constant *ct;
16601664
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
16611665
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
@@ -1722,7 +1726,7 @@ ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry
17221726
if (ignore) {
17231727
/* Check for attempt to redeclare interface constants */
17241728
ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) {
1725-
do_inherit_constant_check(ce, c, key, iface);
1729+
do_inherit_constant_check(ce, c, key);
17261730
} ZEND_HASH_FOREACH_END();
17271731
} else {
17281732
if (ce->num_interfaces >= current_iface_num) {
@@ -1767,7 +1771,7 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry
17671771
}
17681772
/* skip duplications */
17691773
ZEND_HASH_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) {
1770-
do_inherit_constant_check(ce, c, key, iface);
1774+
do_inherit_constant_check(ce, c, key);
17711775
} ZEND_HASH_FOREACH_END();
17721776

17731777
iface = NULL;

0 commit comments

Comments
 (0)