Skip to content

Commit 1ea558c

Browse files
committed
Disallow the usage of the #[AllowDynamicProperties] attribute
1 parent 40edde6 commit 1ea558c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Readonly classes cannot apply the #[AllowDynamicProperties] attribute
3+
--FILE--
4+
<?php
5+
6+
#[AllowDynamicProperties]
7+
readonly class Foo
8+
{
9+
}
10+
11+
?>
12+
--EXPECTF--
13+
Fatal error: Cannot apply #[AllowDynamicProperties] to readonly class Foo in %s on line %d

Zend/zend_attributes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ static void validate_allow_dynamic_properties(
7171
if (scope->ce_flags & ZEND_ACC_INTERFACE) {
7272
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to interface");
7373
}
74+
if (scope->ce_flags & ZEND_ACC_READONLY_CLASS) {
75+
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to readonly class %s",
76+
ZSTR_VAL(scope->name)
77+
);
78+
}
7479
scope->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
7580
}
7681

0 commit comments

Comments
 (0)