From 206c521a1f980c1c422543f3a17fca619e9ec5ee Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 12 Dec 2021 19:53:02 +0100 Subject: [PATCH] Fix GH-7757: Multi-inherited final constant causes fatal error "Diamond" inheritance of final constants is supposed to be supported. Closes GH-7767. --- NEWS | 2 ++ .../final_constants/final_const13.phpt | 18 ++++++++++++++++++ Zend/zend_inheritance.c | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/constants/final_constants/final_const13.phpt diff --git a/NEWS b/NEWS index 28575db948d..c6ae9489f96 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ PHP NEWS on final or abstract interface methods). (ilutov) . Fixed bug #81585 (cached_chunks are not counted to real_size on shutdown). (cmb) + . Fixed bug GH-7757 (Multi-inherited final constant causes fatal error). + (cmb) - Hash: . Fixed bug GH-7759 (Incorrect return types for hash() and hash_hmac()). diff --git a/Zend/tests/constants/final_constants/final_const13.phpt b/Zend/tests/constants/final_constants/final_const13.phpt new file mode 100644 index 00000000000..5e19e8a2126 --- /dev/null +++ b/Zend/tests/constants/final_constants/final_const13.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug GH-7757 (Multi-inherited final constant causes fatal error) +--FILE-- + +--EXPECT-- diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 4903ef4b382..020c5e65539 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1605,7 +1605,7 @@ static bool do_inherit_constant_check( } zend_class_constant *old_constant = Z_PTR_P(zv); - if ((ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_FINAL)) { + if (parent_constant->ce != old_constant->ce && (ZEND_CLASS_CONST_FLAGS(parent_constant) & ZEND_ACC_FINAL)) { zend_error_noreturn(E_COMPILE_ERROR, "%s::%s cannot override final constant %s::%s", ZSTR_VAL(old_constant->ce->name), ZSTR_VAL(name), ZSTR_VAL(parent_constant->ce->name), ZSTR_VAL(name)