mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix GH-17916: Final abstract properties should error
Closes GH-17917.
This commit is contained in:
committed by
Niels Dossche
parent
5ede5415e1
commit
c0857e0d8a
2
NEWS
2
NEWS
@@ -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
|
||||
|
||||
14
Zend/tests/property_hooks/abstract_prop_final.phpt
Normal file
14
Zend/tests/property_hooks/abstract_prop_final.phpt
Normal file
@@ -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
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user