File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ PHP NEWS
72
72
- Reflection:
73
73
. Fixed bug GH-8943 (Fixed Reflection::getModifiersNames() with readonly
74
74
modifier). (Pierrick)
75
+ . Fixed bug GH-8982 (Attribute with TARGET_METHOD is rejected on fake
76
+ closure of method). (ilutov)
75
77
76
78
- Standard:
77
79
. Fixed the crypt_sha256/512 api build with clang > 12. (David Carlier)
Original file line number Diff line number Diff line change @@ -1882,7 +1882,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getAttributes)
1882
1882
1883
1883
GET_REFLECTION_OBJECT_PTR (fptr );
1884
1884
1885
- if (fptr -> common .scope && ! (fptr -> common .fn_flags & ZEND_ACC_CLOSURE ) ) {
1885
+ if (fptr -> common .scope && (fptr -> common .fn_flags & ( ZEND_ACC_CLOSURE | ZEND_ACC_FAKE_CLOSURE )) != ZEND_ACC_CLOSURE ) {
1886
1886
target = ZEND_ATTRIBUTE_TARGET_METHOD ;
1887
1887
} else {
1888
1888
target = ZEND_ATTRIBUTE_TARGET_FUNCTION ;
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-8982 (Attribute target validation fails when read via ReflectionFunction)
3
+ --FILE--
4
+ <?php
5
+
6
+ #[Attribute(Attribute::TARGET_FUNCTION )]
7
+ class F
8
+ {
9
+ }
10
+
11
+ #[Attribute(Attribute::TARGET_METHOD )]
12
+ class M
13
+ {
14
+ }
15
+
16
+ class C
17
+ {
18
+ #[F]
19
+ #[M]
20
+ public function m ()
21
+ {
22
+ }
23
+ }
24
+
25
+ #[F]
26
+ #[M]
27
+ function f () {}
28
+
29
+ function test (string $ attributeClass , $ value ) {
30
+ try {
31
+ var_dump ((new ReflectionFunction ($ value ))->getAttributes ($ attributeClass )[0 ]->newInstance ());
32
+ } catch (Error $ e ) {
33
+ echo $ e ->getMessage (), "\n" ;
34
+ }
35
+ }
36
+
37
+ $ m = [new C (), 'm ' ](...);
38
+ $ f = f (...);
39
+
40
+ test (F::class, $ f );
41
+ test (M::class, $ f );
42
+ test (F::class, $ m );
43
+ test (M::class, $ m );
44
+
45
+ ?>
46
+ --EXPECT--
47
+ object(F)#4 (0) {
48
+ }
49
+ Attribute "M" cannot target function (allowed targets: method)
50
+ Attribute "F" cannot target method (allowed targets: function)
51
+ object(M)#4 (0) {
52
+ }
You can’t perform that action at this time.
0 commit comments