Skip to content

Commit a8d63f5

Browse files
Different instances
1 parent 2a7e677 commit a8d63f5

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--TEST--
2+
ReflectionAttribute::getCurrent() does not return the same exact ReflectionAttribute instance
3+
--FILE--
4+
<?php
5+
6+
#[Attribute]
7+
class Demo {
8+
public function __construct() {
9+
global $originalInstance;
10+
$currentInstance = ReflectionAttribute::getCurrent();
11+
assert($originalInstance !== $currentInstance);
12+
echo "Name:\n";
13+
echo $originalInstance->name . ' -> ' . $currentInstance->name . "\n";
14+
echo "Args:\n";
15+
var_dump($originalInstance->getArguments());
16+
var_dump($currentInstance->getArguments());
17+
assert($originalInstance->getArguments() === $currentInstance->getArguments());
18+
}
19+
}
20+
21+
#[Demo("foo", true, 123)]
22+
class WithDemo {}
23+
24+
$case = new ReflectionClass(WithDemo::class);
25+
$originalInstance = $case->getAttributes()[0];
26+
$originalInstance->newInstance();
27+
28+
?>
29+
--EXPECT--
30+
Name:
31+
Demo -> Demo
32+
Args:
33+
array(3) {
34+
[0]=>
35+
string(3) "foo"
36+
[1]=>
37+
bool(true)
38+
[2]=>
39+
int(123)
40+
}
41+
array(3) {
42+
[0]=>
43+
string(3) "foo"
44+
[1]=>
45+
bool(true)
46+
[2]=>
47+
int(123)
48+
}

0 commit comments

Comments
 (0)