1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

#[AllowDynamicProperties] validation: improve error messages (#15734)

For traits and interfaces, include the name of the relevant trait (or
interface) in the error message, the same way it is included for readonly
classes.
This commit is contained in:
DanielEScherzer
2024-09-04 13:54:42 -07:00
committed by GitHub
parent 1d36927127
commit f9d01e46fe
3 changed files with 8 additions and 4 deletions

View File

@@ -8,4 +8,4 @@ interface Test {}
?>
--EXPECTF--
Fatal error: Cannot apply #[AllowDynamicProperties] to interface in %s on line %d
Fatal error: Cannot apply #[AllowDynamicProperties] to interface Test in %s on line %d

View File

@@ -8,4 +8,4 @@ trait Test {}
?>
--EXPECTF--
Fatal error: Cannot apply #[AllowDynamicProperties] to trait in %s on line %d
Fatal error: Cannot apply #[AllowDynamicProperties] to trait Test in %s on line %d

View File

@@ -72,10 +72,14 @@ static void validate_allow_dynamic_properties(
zend_attribute *attr, uint32_t target, zend_class_entry *scope)
{
if (scope->ce_flags & ZEND_ACC_TRAIT) {
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to trait");
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to trait %s",
ZSTR_VAL(scope->name)
);
}
if (scope->ce_flags & ZEND_ACC_INTERFACE) {
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to interface");
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to interface %s",
ZSTR_VAL(scope->name)
);
}
if (scope->ce_flags & ZEND_ACC_READONLY_CLASS) {
zend_error_noreturn(E_ERROR, "Cannot apply #[AllowDynamicProperties] to readonly class %s",