diff --git a/NEWS b/NEWS index 8cf60aeedf885..b86e31ec70fa1 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? ????, PHP 8.3.0alpha2 +- Core: + . Fix GH-11388 (Allow "final" modifier when importing a method from a trait). + (nielsdos) 08 Jun 2023, PHP 8.3.0alpha1 diff --git a/UPGRADING b/UPGRADING index 643c8d68ab901..1320b919206c9 100644 --- a/UPGRADING +++ b/UPGRADING @@ -63,6 +63,7 @@ PHP 8.3 UPGRADE NOTES . Class, interface, trait, and enum constants now support type declarations. RFC: https://wiki.php.net/rfc/typed_class_constants . Closures created from magic methods can now accept named arguments. + . The final modifier may now be used when using a method from a trait. - Posix . posix_getrlimit() now takes an optional $res parameter to allow fetching a diff --git a/Zend/tests/traits/language019.phpt b/Zend/tests/traits/language019.phpt index 299f661db9b38..e64ec08909f5d 100644 --- a/Zend/tests/traits/language019.phpt +++ b/Zend/tests/traits/language019.phpt @@ -10,6 +10,9 @@ class C1 { T1::foo as final; } } +class C2 extends C1 { + public function foo() {} +} ?> --EXPECTF-- -Fatal error: Cannot use "final" as method modifier in trait alias in %s on line %d +Fatal error: Cannot override final method C1::foo() in %s on line %d diff --git a/Zend/tests/traits/language020.phpt b/Zend/tests/traits/language020.phpt new file mode 100644 index 0000000000000..bbfa5c82652c2 --- /dev/null +++ b/Zend/tests/traits/language020.phpt @@ -0,0 +1,21 @@ +--TEST-- +final alias - positive test variation +--FILE-- +foo(); +?> +--EXPECT-- +Done diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5984206a8b136..b6a4840ab558d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7727,8 +7727,6 @@ static void zend_check_trait_alias_modifiers(uint32_t attr) /* {{{ */ zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"static\" as method modifier in trait alias"); } else if (attr & ZEND_ACC_ABSTRACT) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"abstract\" as method modifier in trait alias"); - } else if (attr & ZEND_ACC_FINAL) { - zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"final\" as method modifier in trait alias"); } } /* }}} */