Skip to content

Commit 148d8df

Browse files
committed
Added scope resolution test case.
1 parent d9330be commit 148d8df

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
--TEST--
2+
Attributes make use of correct scope.
3+
--FILE--
4+
<?php
5+
6+
<<A1(self::class, self::FOO)>>
7+
class C1
8+
{
9+
<<A1(self::class, self::FOO)>>
10+
private const FOO = 'foo';
11+
12+
<<A1(self::class, self::FOO)>>
13+
public $a;
14+
15+
<<A1(self::class, self::FOO)>>
16+
public function bar(<<A1(self::class, self::FOO)>> $p) { }
17+
}
18+
19+
$ref = new \ReflectionClass(C1::class);
20+
print_r($ref->getAttributes()[0]->getArguments());
21+
print_r($ref->getReflectionConstant('FOO')->getAttributes()[0]->getArguments());
22+
print_r($ref->getProperty('a')->getAttributes()[0]->getArguments());
23+
print_r($ref->getMethod('bar')->getAttributes()[0]->getArguments());
24+
print_r($ref->getMethod('bar')->getParameters()[0]->getAttributes()[0]->getArguments());
25+
26+
echo "\n";
27+
28+
class C2
29+
{
30+
private const FOO = 'foo';
31+
32+
public static function foo()
33+
{
34+
return <<A1(self::class, self::FOO)>> function (<<A1(self::class, self::FOO)>> $p) { };
35+
}
36+
}
37+
38+
$ref = new \ReflectionFunction(C2::foo());
39+
print_r($ref->getAttributes()[0]->getArguments());
40+
print_r($ref->getParameters()[0]->getAttributes()[0]->getArguments());
41+
42+
echo "\n";
43+
44+
class C3
45+
{
46+
private const FOO = 'foo';
47+
48+
public static function foo()
49+
{
50+
return new <<A1(self::class, self::FOO)>> class() {
51+
private const FOO = 'bar';
52+
53+
<<A1(self::class, self::FOO)>>
54+
public function bar() { }
55+
};
56+
}
57+
}
58+
59+
$obj = C3::foo();
60+
$ref = new \ReflectionObject($obj);
61+
$name = $ref->getMethod('bar')->getAttributes()[0]->getArguments()[0];
62+
63+
print_r($ref->getAttributes()[0]->getArguments());
64+
var_dump($name == get_class($obj));
65+
var_dump($ref->getMethod('bar')->getAttributes()[0]->getArguments()[1]);
66+
67+
?>
68+
--EXPECT--
69+
Array
70+
(
71+
[0] => C1
72+
[1] => foo
73+
)
74+
Array
75+
(
76+
[0] => C1
77+
[1] => foo
78+
)
79+
Array
80+
(
81+
[0] => C1
82+
[1] => foo
83+
)
84+
Array
85+
(
86+
[0] => C1
87+
[1] => foo
88+
)
89+
Array
90+
(
91+
[0] => C1
92+
[1] => foo
93+
)
94+
95+
Array
96+
(
97+
[0] => C2
98+
[1] => foo
99+
)
100+
Array
101+
(
102+
[0] => C2
103+
[1] => foo
104+
)
105+
106+
Array
107+
(
108+
[0] => C3
109+
[1] => foo
110+
)
111+
bool(true)
112+
string(3) "bar"

0 commit comments

Comments
 (0)