1
0
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:
Ilija Tovilo
2024-08-19 14:58:55 +02:00
committed by GitHub
parent 770616b823
commit 36b1977415
4 changed files with 32 additions and 5 deletions

2
NEWS
View File

@@ -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

View 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

View 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

View File

@@ -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);