Skip to content

Commit 206c521

Browse files
committed
Fix GH-7757: Multi-inherited final constant causes fatal error
"Diamond" inheritance of final constants is supposed to be supported. Closes GH-7767.
1 parent 577358b commit 206c521

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
on final or abstract interface methods). (ilutov)
1212
. Fixed bug #81585 (cached_chunks are not counted to real_size on shutdown).
1313
(cmb)
14+
. Fixed bug GH-7757 (Multi-inherited final constant causes fatal error).
15+
(cmb)
1416

1517
- Hash:
1618
. Fixed bug GH-7759 (Incorrect return types for hash() and hash_hmac()).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug GH-7757 (Multi-inherited final constant causes fatal error)
3+
--FILE--
4+
<?php
5+
interface EntityInterface {
6+
final public const TEST = 'this';
7+
}
8+
9+
interface KeyInterface extends EntityInterface {
10+
}
11+
12+
interface StringableInterface extends EntityInterface {
13+
}
14+
15+
class SomeTestClass implements KeyInterface, StringableInterface {
16+
}
17+
?>
18+
--EXPECT--

Zend/zend_inheritance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ static bool do_inherit_constant_check(
16051605
}
16061606

16071607
zend_class_constant *old_constant = Z_PTR_P(zv);
1608-
if ((ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_FINAL)) {
1608+
if (parent_constant->ce != old_constant->ce && (ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_FINAL)) {
16091609
zend_error_noreturn(E_COMPILE_ERROR, "%s::%s cannot override final constant %s::%s",
16101610
ZSTR_VAL(old_constant->ce->name), ZSTR_VAL(name),
16111611
ZSTR_VAL(parent_constant->ce->name), ZSTR_VAL(name)

0 commit comments

Comments
 (0)