-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collision of interface constant and trait constant should not produce fatal error #16198
Comments
Well, could go beyond this error with the following patch Zend/zend_inheritance.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index 88f1d3447c..fed00589f4 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -2689,7 +2689,7 @@ static void emit_incompatible_trait_constant_error(
static bool do_trait_constant_check(
zend_class_entry *ce, zend_class_constant *trait_constant, zend_string *name, zend_class_entry **traits, size_t current_trait
) {
- uint32_t flags_mask = ZEND_ACC_PPP_MASK | ZEND_ACC_FINAL;
+ uint32_t flags_mask = ZEND_ACC_PPP_MASK;
zval *zv = zend_hash_find_known_hash(&ce->constants_table, name);
if (zv == NULL) { But then the compilation would fail, because trait constants are apparently invariant: php-src/Zend/zend_inheritance.c Lines 2711 to 2713 in 2d8a93c
When lifting the restriction, the compilation would then fail because the constant values are not compatible (i.e. not the same, as is checked in this case): php-src/Zend/zend_inheritance.c Lines 2719 to 2723 in 2d8a93c
|
@cmb69 Thank you, so the fix requires more dev or it can not be fixed? |
Hmm, I think it can be "fixed", but I'm not sure whether the current implementation is by design. Maybe @kocsismate can explain the rationale of the current implementation. |
related to #16198 Thank you @iluuu1994 |
What is the next step to have the fix in the next minor release please? |
Nothing on your side. I need to think through the consequences of my patch when I have the time. |
Description
The following code:
Resulted in this output:
But I expected this output instead:
This bug is related to the ticket #9271.
The behavior of a trait is to copy code into class, so if we can do something without trait and without error, it should be possible to do the same thing but with trait. I don't understand why I get this error with my code.
PHP Version
PHP 8.3.9
Operating System
Ubuntu 22.04
The text was updated successfully, but these errors were encountered: