Skip to content

Commit b4dad15

Browse files
committed
Add test + improve error message for static properties of readonly classes
1 parent 809b093 commit b4dad15

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
@@ -7250,6 +7250,12 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
72507250
zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
72517251
}
72527252

7253+
if ((ce->ce_flags & ZEND_ACC_READONLY_CLASS) && (flags & ZEND_ACC_STATIC)) {
7254+
zend_error_noreturn(E_COMPILE_ERROR, "Readonly class %s cannot declare static properties",
7255+
ZSTR_VAL(ce->name)
7256+
);
7257+
}
7258+
72537259
for (i = 0; i < children; ++i) {
72547260
zend_property_info *info;
72557261
zend_ast *prop_ast = list->child[i];

0 commit comments

Comments
 (0)