@@ -89,11 +89,6 @@ static zend_string *validate_allow_dynamic_properties(
8989 smart_str_append_printf (& str , msg , ZSTR_VAL (scope -> name ));
9090 return smart_str_extract (& str );
9191 }
92- if (target & ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ) {
93- // Should have passed the first time
94- ZEND_ASSERT ((scope -> ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES ) != 0 );
95- return NULL ;
96- }
9792 scope -> ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES ;
9893 return NULL ;
9994}
@@ -221,23 +216,15 @@ ZEND_METHOD(Deprecated, __construct)
221216static zend_string * validate_nodiscard (
222217 zend_attribute * attr , uint32_t target , zend_class_entry * scope )
223218{
224- /* There isn't an easy way to identify the *method* that the attribute is
225- * applied to in a manner that works during both compilation (normal
226- * validation) and runtime (delayed validation). So, handle them separately. */
227- if (CG (in_compilation )) {
228- ZEND_ASSERT ((target & ZEND_ATTRIBUTE_DELAYED_TARGET_VALIDATION ) == 0 );
229- zend_op_array * op_array = CG (active_op_array );
230- const zend_string * prop_info_name = CG (context ).active_property_info_name ;
231- if (prop_info_name == NULL ) {
232- op_array -> fn_flags |= ZEND_ACC_NODISCARD ;
233- return NULL ;
234- }
235- // Applied to a hook, either throw or ignore
236- return ZSTR_INIT_LITERAL ("#[\\NoDiscard] is not supported for property hooks" , 0 );
219+ ZEND_ASSERT (CG (in_compilation ));
220+ zend_op_array * op_array = CG (active_op_array );
221+ const zend_string * prop_info_name = CG (context ).active_property_info_name ;
222+ if (prop_info_name == NULL ) {
223+ op_array -> fn_flags |= ZEND_ACC_NODISCARD ;
224+ return NULL ;
237225 }
238- /* At runtime, no way to identify the target method; Reflection will handle
239- * throwing the error if needed. */
240- return NULL ;
226+ // Applied to a hook
227+ return ZSTR_INIT_LITERAL ("#[\\NoDiscard] is not supported for property hooks" , 0 );
241228}
242229
243230ZEND_METHOD (NoDiscard , __construct )
@@ -467,6 +454,9 @@ static void attr_free(zval *v)
467454
468455 zend_string_release (attr -> name );
469456 zend_string_release (attr -> lcname );
457+ if (attr -> validation_error != NULL ) {
458+ zend_string_release (attr -> validation_error );
459+ }
470460
471461 for (uint32_t i = 0 ; i < attr -> argc ; i ++ ) {
472462 if (attr -> args [i ].name ) {
@@ -499,6 +489,7 @@ ZEND_API zend_attribute *zend_add_attribute(HashTable **attributes, zend_string
499489 }
500490
501491 attr -> lcname = zend_string_tolower_ex (attr -> name , persistent );
492+ attr -> validation_error = NULL ;
502493 attr -> flags = flags ;
503494 attr -> lineno = lineno ;
504495 attr -> offset = offset ;
0 commit comments