-
Notifications
You must be signed in to change notification settings - Fork 35
/
test.php
168 lines (137 loc) · 2.42 KB
/
test.php
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace Bar;
use Swoole\Coroutine;
use function Swoole\Coroutine\run;
function test1() {
echo 'test1' . PHP_EOL;
test2();
}
function test2() {
return;
echo 'test2' . PHP_EOL;
}
function test3() {
return [
['hello'],
['world'],
[new Foo(1)],
];
}
// Suppose the business code calls a function to determine whether to end the loop,
// but the business code always returns false
function test4() {
return false;
}
function test5() {
sleep(1);
}
class Foo3
{
public $a;
private $c;
public function __construct()
{
$this->a = "hello";
$this->c = ['a', 'b'];
}
}
class Foo2
{
public $a;
public $b;
private $foo3;
/**
* Map of entries that are already resolved.
*
* @var array
*/
private $resolvedEntries = [];
public function test()
{
return [
['hello'],
['world'],
[new Foo(1)],
];
}
public function __construct()
{
$this->a = "hello";
$this->resolvedEntries = [
'aaa' => new Foo3(),
'bbb' => [4, 5, 6],
];
$this->foo3 = new Foo3();
}
}
class Foo
{
public $a;
public $foo2;
public $arr;
public function test()
{
return [
['hello'],
['world'],
[new Foo(1)],
];
}
public function __construct($a)
{
$this->arr = [
self::class => [self::class => [self::class => 1]],
];
$this->a = "hello";
$this->foo2 = new Foo2();
}
}
test5();
$b = true;
$b = false;
$i = 0;
$j = 1;
$j = 2;
$k = [];
$k = ['a' => ['b' => [1, 2, 3]]];
$k = [
['hello'],
['world'],
];
while (true) {
if ($i++ == 5) {
$k = ['hello' => 1, "world" => 1.1];
$j = 5;
}
if ($i == 10) {
$k = ['hello', 'world'];
$j = 10;
break;
}
}
$a = 0;
while (true) {
$a++;
if (test4() || $a > 50000) {
break;
}
}
echo 'hello' . PHP_EOL;
require __DIR__ . '/header.php';
echo 'world' . PHP_EOL;
$foo = new Foo(2);
run(function () {
Coroutine::create(function () {
$i = 1;
test1();
Coroutine::yield();
$i = 2;
$a = ['a' => 1, 'b' => 2];
var_dump($a);
});
Coroutine::create(function () {
$i = 3;
Coroutine::resume(2);
$i = 4;
});
});