Skip to content

Commit eb530c1

Browse files
committed
Allow final modifier when using a method from a trait
Fixes GH-11388. Following https://wiki.php.net/rfc/horizontalreuse which introduced traits, this should be allowed. The implementation was refactored in 3f8c729. That commit is the first time the "final" check appears AFAICT, but no reason was given for why. That commit seems to have landed in 5.4.11 and the NEWS for that version doesn't seem to mention something relevant to the behaviour change. This patch removes the restriction of the final modifier.
1 parent 0561783 commit eb530c1

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PHP 8.3 UPGRADE NOTES
6363
. Class, interface, trait, and enum constants now support type
6464
declarations. RFC: https://wiki.php.net/rfc/typed_class_constants
6565
. Closures created from magic methods can now accept named arguments.
66+
. The final modifier may now be used when using a method from a trait.
6667

6768
- Posix
6869
. posix_getrlimit() now takes an optional $res parameter to allow fetching a

Zend/tests/traits/language019.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class C1 {
1010
T1::foo as final;
1111
}
1212
}
13+
class C2 extends C1 {
14+
public function foo() {}
15+
}
1316
?>
1417
--EXPECTF--
15-
Fatal error: Cannot use "final" as method modifier in trait alias in %s on line %d
18+
Fatal error: Cannot override final method C1::foo() in %s on line %d

Zend/zend_compile.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7727,8 +7727,6 @@ static void zend_check_trait_alias_modifiers(uint32_t attr) /* {{{ */
77277727
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"static\" as method modifier in trait alias");
77287728
} else if (attr & ZEND_ACC_ABSTRACT) {
77297729
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"abstract\" as method modifier in trait alias");
7730-
} else if (attr & ZEND_ACC_FINAL) {
7731-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"final\" as method modifier in trait alias");
77327730
}
77337731
}
77347732
/* }}} */

0 commit comments

Comments
 (0)