php-src/Zend/tests/attributes
Ilija Tovilo f8d1864bbb
Delay #[Attribute] arg validation until runtime
Fixes GH-13970
Closes GH-14105

We cannot validate at compile-time for multiple reasons:

* Evaluating the argument naively with zend_get_attribute_value can lead to code
  execution at compile time through the new expression, leading to possible
  reentrance of the compiler.
* Even if the evaluation was possible, it would need to be restricted to the
  current file, because constant values coming from other files can change
  without affecting the current compilation unit. For this reason, validation
  would need to be repeated at runtime anyway.
* Enums cannot be instantiated at compile-time (the actual bug report). This
  could be allowed here, because the value is immediately destroyed. But given
  the other issues, this won't be needed.

Instead, we just move it to runtime entirely. It's only needed for
ReflectionAttribute::newInstance(), which is not particularly a hot path. The
checks are also simple.
2024-05-06 12:38:56 +02:00
..
001_placement.phpt Run tidy 2020-09-18 14:28:32 +02:00
002_rfcexample.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
003_ast_nodes.phpt Run tidy 2020-09-18 14:28:32 +02:00
004_name_resolution.phpt Fix detection of code outside namespace 2020-09-21 12:37:44 +02:00
005_objects.phpt Honor strict_types=1 for attributes, improve backtraces 2020-09-27 10:42:58 +02:00
006_filter.phpt Run tidy 2020-09-18 14:28:32 +02:00
007_self_reflect_attribute.phpt Pass flags to #[Attribute] on internal attributes 2021-05-21 11:40:23 +02:00
008_wrong_attribution.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
009_doctrine_annotations_example.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
010_unsupported_const_expression.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
011_inheritance.phpt Run tidy 2020-09-18 14:28:32 +02:00
012_ast_export.phpt Run tidy 2020-09-18 14:28:32 +02:00
013_class_scope.phpt Run tidy 2020-09-18 14:28:32 +02:00
014_class_const_group.phpt Allow attributes to be applied to property/constant groups 2020-09-27 11:35:48 +02:00
015_property_group.phpt Allow attributes to be applied to property/constant groups 2020-09-27 11:35:48 +02:00
016_custom_attribute_validation.phpt Migrate SKIPIF -> EXTENSIONS (#7138) 2021-06-11 11:57:42 +02:00
017_closure_scope.phpt Run tidy 2020-09-18 14:28:32 +02:00
018_fatal_error_in_argument.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
019_variable_attribute_name.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
020_userland_attribute_validation.phpt Run tidy 2020-09-18 14:28:32 +02:00
021_attribute_flags_type_is_validated.phpt Delay #[Attribute] arg validation until runtime 2024-05-06 12:38:56 +02:00
022_attribute_flags_value_is_validated.phpt Delay #[Attribute] arg validation until runtime 2024-05-06 12:38:56 +02:00
023_ast_node_in_validation.phpt Delay #[Attribute] arg validation until runtime 2024-05-06 12:38:56 +02:00
024_internal_target_validation.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
025_internal_repeatable_validation.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
026_unpack_in_args.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
027_trailing_comma_args.phpt Run tidy 2020-09-18 14:28:32 +02:00
028_grouped.phpt Change Attribute Syntax from @@ to #[] 2020-09-02 20:26:50 +02:00
029_reflect_internal_symbols.phpt Initialize attributes for internal functions 2020-09-21 10:50:29 +02:00
030_strict_types.inc Honor strict_types=1 for attributes, improve backtraces 2020-09-27 10:42:58 +02:00
030_strict_types.phpt Honor strict_types=1 for attributes, improve backtraces 2020-09-27 10:42:58 +02:00
031_backtrace.phpt Use common formatting for backtraces (#6977) 2021-05-18 11:43:37 +02:00
032_attribute_validation_scope.phpt Delay #[Attribute] arg validation until runtime 2024-05-06 12:38:56 +02:00
033_attribute_flags_type_is_not_validated_at_comp_time.phpt Delay #[Attribute] arg validation until runtime 2024-05-06 12:38:56 +02:00
gh8421.phpt Fix GH-8421: Attributes that target functions are not valid for anonymous functions defined within a method 2022-04-23 11:16:28 +02:00