Skip to content

Commit 4ede80c

Browse files
committed
Test static variable in parent trait method
1 parent d8ff45c commit 4ede80c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Behavior of static variables in parent trait method
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
public function foo()
8+
{
9+
var_dump(__CLASS__);
10+
11+
static $v = null;
12+
if ($v === null) {
13+
$v = random_bytes(64);
14+
}
15+
16+
return $v;
17+
}
18+
}
19+
20+
class A { use T; }
21+
class B extends A {}
22+
class C extends A { use T; }
23+
class D { use T; }
24+
25+
$a = (new A())->foo();
26+
var_dump($a === (new A())->foo());
27+
var_dump($a === (new B())->foo());
28+
$c = new C();
29+
var_dump($a === $c->foo());
30+
var_dump($a === (new \ReflectionMethod(A::class, 'foo'))->invoke($c));
31+
var_dump($a === (new D())->foo());
32+
33+
?>
34+
--EXPECT--
35+
string(1) "A"
36+
string(1) "A"
37+
bool(true)
38+
string(1) "A"
39+
bool(true)
40+
string(1) "C"
41+
bool(false)
42+
string(1) "A"
43+
bool(true)
44+
string(1) "D"
45+
bool(false)

0 commit comments

Comments
 (0)