mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix missing compile error when declaring hooked props on readonly classes (GH-15439)
Fixes GH-15419
This commit is contained in:
2
NEWS
2
NEWS
@@ -7,6 +7,8 @@ PHP NEWS
|
||||
(zeriyoshi)
|
||||
. Fixed bug GH-15438 (Hooks on constructor promoted properties without
|
||||
visibility are ignored). (ilutov)
|
||||
. Fixed bug GH-15419 (Missing readonly+hook incompatibility check for readonly
|
||||
classes). (ilutov)
|
||||
|
||||
15 Aug 2024, PHP 8.4.0beta3
|
||||
|
||||
|
||||
12
Zend/tests/property_hooks/gh15419_1.phpt
Normal file
12
Zend/tests/property_hooks/gh15419_1.phpt
Normal file
@@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
GH-15419: Readonly classes may not declare properties with hooks
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
readonly class C {
|
||||
public int $prop { set => $value; }
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Hooked properties cannot be readonly in %s on line %d
|
||||
14
Zend/tests/property_hooks/gh15419_2.phpt
Normal file
14
Zend/tests/property_hooks/gh15419_2.phpt
Normal file
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
GH-15419: Readonly classes may not declare promoted properties with hooks
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
readonly class C {
|
||||
public function __construct(
|
||||
public int $prop { set => $value; },
|
||||
) {}
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Hooked properties cannot be readonly in %s on line %d
|
||||
@@ -8385,6 +8385,10 @@ static void zend_compile_property_hooks(
|
||||
{
|
||||
zend_class_entry *ce = CG(active_class_entry);
|
||||
|
||||
if (prop_info->flags & ZEND_ACC_READONLY) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Hooked properties cannot be readonly");
|
||||
}
|
||||
|
||||
if (hooks->children == 0) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR, "Property hook list cannot be empty");
|
||||
}
|
||||
@@ -8608,11 +8612,6 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
|
||||
ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
|
||||
}
|
||||
|
||||
if (hooks_ast && (flags & ZEND_ACC_READONLY)) {
|
||||
zend_error_noreturn(E_COMPILE_ERROR,
|
||||
"Hooked properties cannot be readonly");
|
||||
}
|
||||
|
||||
if (type_ast) {
|
||||
type = zend_compile_typename(type_ast);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user