Skip to content

Commit 2a7e677

Browse files
Test specific instance
1 parent b7435a0 commit 2a7e677

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
--TEST--
2+
ReflectionAttribute::getCurrent() returns the ReflectionAttribute for the specific usage
3+
--FILE--
4+
<?php
5+
6+
#[Attribute(Attribute::TARGET_ALL|Attribute::IS_REPEATABLE)]
7+
class Demo {
8+
public function __construct($args) {
9+
var_dump($args);
10+
var_dump(ReflectionAttribute::getCurrent()->getArguments());
11+
}
12+
}
13+
14+
#[Demo("one string param")]
15+
#[Demo(true, 123), Demo(null)]
16+
const GLOBAL_CONSTANT = true;
17+
18+
$case = new ReflectionConstant('GLOBAL_CONSTANT');
19+
echo $case;
20+
echo "\n";
21+
foreach ($case->getAttributes() as $attrib) {
22+
var_dump($attrib->getArguments());
23+
$attrib->newInstance();
24+
echo "\n";
25+
}
26+
27+
?>
28+
--EXPECT--
29+
Constant [ bool GLOBAL_CONSTANT ] { 1 }
30+
31+
array(1) {
32+
[0]=>
33+
string(16) "one string param"
34+
}
35+
string(16) "one string param"
36+
array(1) {
37+
[0]=>
38+
string(16) "one string param"
39+
}
40+
41+
array(2) {
42+
[0]=>
43+
bool(true)
44+
[1]=>
45+
int(123)
46+
}
47+
bool(true)
48+
array(2) {
49+
[0]=>
50+
bool(true)
51+
[1]=>
52+
int(123)
53+
}
54+
55+
array(1) {
56+
[0]=>
57+
NULL
58+
}
59+
NULL
60+
array(1) {
61+
[0]=>
62+
NULL
63+
}

0 commit comments

Comments
 (0)