Skip to content

Allow final modifier when using a method from a trait #11394

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

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Zend/tests/traits/language019.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions Zend/tests/traits/language020.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
final alias - positive test variation
--FILE--
<?php
trait T1 {
function foo() {
echo "Done\n";
}
}
class C1 {
use T1 {
T1::foo as final;
}
}
class C2 extends C1 {
public function bar() {}
}
(new C2)->foo();
?>
--EXPECT--
Done
2 changes: 0 additions & 2 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
/* }}} */
Expand Down