Fix GH-15731: Prevent #[AllowDynamicProperties] on enums (#15733)

This commit is contained in:
DanielEScherzer 2024-09-04 15:56:18 -07:00 committed by GitHub
parent 6435bb5ae1
commit 5a18279b5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,11 @@
--TEST--
#[AllowDynamicProperties] cannot be applied to enum (GH-15731)
--FILE--
<?php
#[AllowDynamicProperties]
enum Test {}
?>
--EXPECTF--
Fatal error: Cannot apply #[AllowDynamicProperties] to enum Test in %s on line %d

View File

@ -86,6 +86,11 @@ static void validate_allow_dynamic_properties(
ZSTR_VAL(scope->name)
);
}
if (scope->ce_flags & ZEND_ACC_ENUM) {
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to enum %s",
ZSTR_VAL(scope->name)
);
}
scope->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES;
}