Skip to content

Commit 229c1eb

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17916: Final abstract properties should error
2 parents 8e9df32 + c0857e0 commit 229c1eb

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-17916: Abstract property cannot be marked as final
3+
--FILE--
4+
<?php
5+
6+
abstract class Foo {
7+
final abstract public string $bar {
8+
get;
9+
}
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Cannot use the final modifier on an abstract property in %s on line %d

Zend/zend_compile.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,17 @@ uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag, zend_modifi
10311031
"Multiple access type modifiers are not allowed", 0);
10321032
return 0;
10331033
}
1034-
if (target == ZEND_MODIFIER_TARGET_METHOD && (new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
1035-
zend_throw_exception(zend_ce_compile_error,
1036-
"Cannot use the final modifier on an abstract method", 0);
1037-
return 0;
1034+
if ((new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
1035+
if (target == ZEND_MODIFIER_TARGET_METHOD) {
1036+
zend_throw_exception(zend_ce_compile_error,
1037+
"Cannot use the final modifier on an abstract method", 0);
1038+
return 0;
1039+
}
1040+
if (target == ZEND_MODIFIER_TARGET_PROPERTY) {
1041+
zend_throw_exception(zend_ce_compile_error,
1042+
"Cannot use the final modifier on an abstract property", 0);
1043+
return 0;
1044+
}
10381045
}
10391046
if (target == ZEND_MODIFIER_TARGET_PROPERTY || target == ZEND_MODIFIER_TARGET_CPP) {
10401047
if ((flags & ZEND_ACC_PPP_SET_MASK) && (new_flag & ZEND_ACC_PPP_SET_MASK)) {

0 commit comments

Comments
 (0)