File: 001_placement.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (134 lines) | stat: -rw-r--r-- 1,842 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
--TEST--
Attributes can be placed on all supported elements.
--FILE--
<?php

#[A1(1)]
class Foo
{
    #[A1(2)]
    public const FOO = 'foo';

    #[A1(3)]
    public $x;

    #[A1(4)]
    public function foo(#[A1(5)] $a, #[A1(6)] $b) { }
}

$object = new #[A1(7)] class () { };

#[A1(8)]
function f1() { }

$f2 = #[A1(9)] function () { };

$f3 = #[A1(10)] fn () => 1;

$ref = new \ReflectionClass(Foo::class);

$sources = [
    $ref,
    $ref->getReflectionConstant('FOO'),
    $ref->getProperty('x'),
    $ref->getMethod('foo'),
    $ref->getMethod('foo')->getParameters()[0],
    $ref->getMethod('foo')->getParameters()[1],
    new \ReflectionObject($object),
    new \ReflectionFunction('f1'),
    new \ReflectionFunction($f2),
    new \ReflectionFunction($f3)
];

foreach ($sources as $r) {
    $attr = $r->getAttributes();
    var_dump(get_class($r), count($attr));

    foreach ($attr as $a) {
        var_dump($a->getName(), $a->getArguments());
    }

    echo "\n";
}

?>
--EXPECT--
string(15) "ReflectionClass"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(1)
}

string(23) "ReflectionClassConstant"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(2)
}

string(18) "ReflectionProperty"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(3)
}

string(16) "ReflectionMethod"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(4)
}

string(19) "ReflectionParameter"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(5)
}

string(19) "ReflectionParameter"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(6)
}

string(16) "ReflectionObject"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(7)
}

string(18) "ReflectionFunction"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(8)
}

string(18) "ReflectionFunction"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(9)
}

string(18) "ReflectionFunction"
int(1)
string(2) "A1"
array(1) {
  [0]=>
  int(10)
}