Skip to content

Commit f8a297d

Browse files
committed
Add test + improve error message for static properties of readonly classes
1 parent e3dc780 commit f8a297d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Declaring static property for a readonly class is forbidden
3+
--FILE--
4+
<?php
5+
6+
readonly class Foo
7+
{
8+
public static int $bar;
9+
}
10+
11+
?>
12+
--EXPECTF--
13+
Fatal error: Readonly class Foo cannot declare static properties in %s on line %d

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7247,6 +7247,12 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
72477247
zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
72487248
}
72497249

7250+
if ((ce->ce_flags & ZEND_ACC_READONLY_CLASS) && (flags & ZEND_ACC_STATIC)) {
7251+
zend_error_noreturn(E_COMPILE_ERROR, "Readonly class %s cannot declare static properties",
7252+
ZSTR_VAL(ce->name)
7253+
);
7254+
}
7255+
72507256
for (i = 0; i < children; ++i) {
72517257
zend_property_info *info;
72527258
zend_ast *prop_ast = list->child[i];

0 commit comments

Comments
 (0)