Skip to content
Closed
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ PHP NEWS
`__callStatic` is allowed). (timwolla)
. Fixed bug GH-17713 (ReflectionProperty::getRawValue() and related methods
may call hooks of overridden properties). (Arnaud)
. Fixed bug GH-17916 (Final abstract properties should error).
(DanielEScherzer)

- DOM:
. Fixed bug GH-17609 (Typo in error message: Dom\NO_DEFAULT_NS instead of
Expand Down
14 changes: 14 additions & 0 deletions Zend/tests/property_hooks/abstract_prop_final.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-17916: Abstract property cannot be marked as final
--FILE--
<?php

abstract class Foo {
final abstract public string $bar {
get;
}
}

?>
--EXPECTF--
Fatal error: Cannot use the final modifier on an abstract property in %s on line %d
15 changes: 11 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,10 +1036,17 @@ uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag, zend_modifi
"Multiple readonly modifiers are not allowed", 0);
return 0;
}
if (target == ZEND_MODIFIER_TARGET_METHOD && (new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
zend_throw_exception(zend_ce_compile_error,
"Cannot use the final modifier on an abstract method", 0);
return 0;
if ((new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
if (target == ZEND_MODIFIER_TARGET_METHOD) {
zend_throw_exception(zend_ce_compile_error,
"Cannot use the final modifier on an abstract method", 0);
return 0;
}
if (target == ZEND_MODIFIER_TARGET_PROPERTY) {
zend_throw_exception(zend_ce_compile_error,
"Cannot use the final modifier on an abstract property", 0);
return 0;
}
}
if (target == ZEND_MODIFIER_TARGET_PROPERTY || target == ZEND_MODIFIER_TARGET_CPP) {
if ((flags & ZEND_ACC_PPP_SET_MASK) && (new_flag & ZEND_ACC_PPP_SET_MASK)) {
Expand Down
Loading