Remove array literals from quick tests
[hiphop-php.git] / hphp / test / quick / generator_vars.php
blob09ef42492ebc05a95d0d1d05f782486dbbef5008
1 <?hh
3 class logger {
4 static $x = 0;
5 private $idx;
6 function __construct() {
7 $this->idx = self::$x++;
8 printf("logger %d constructing\n", $this->idx);
12 function create() {
13 $x = 5;
14 yield $x;
15 $s = 'foo';
16 yield $s;
17 $foo = 1234;
18 $z = $foo;
19 yield $z;
20 yield $foo;
23 function unusedarg($x, $y) {
24 $z = 5;
25 yield darray['x' => $x, 'z' => $z];
26 $s = 'foo';
27 yield 'almost there';
28 $foo = 'inside foo';
29 yield darray['foo' => $foo, 's' => $s];
30 yield darray['x' => $x, 'y' => $y, 'foo' => $foo, 'z' => $z];
33 function dumpgen($g) {
34 foreach ($g as $v) {
35 var_dump($v);
39 function getargs(...$args) {
40 yield 0xdeadbeef;
41 yield $args;
42 yield $args[3];
45 function genthrow() {
46 throw new Exception();
47 yield 5;
50 function manylocals() {
51 $a = 1;
52 $b = 2;
53 $c = 3;
54 $d = 4;
55 $e = 5;
56 $f = 6;
57 $g = 7;
58 $h = 8;
59 $i = 9;
60 $j = 10;
61 $k = 11;
62 $l = 12;
63 $a = yield darray['a' => $a, 'b' => $b, 'c' => $c, 'd' => $d, 'e' => $e, 'f' => $f, 'g' => $g, 'h' => $h, 'i' => $i, 'j' => $j, 'k' => $k, 'l' => $l];
64 $b = 0xdeadbeef;
65 $c = yield darray['a' => $a, 'b' => $b, 'c' => $c, 'd' => $d, 'e' => $e, 'f' => $f, 'g' => $g, 'h' => $h, 'i' => $i, 'j' => $j, 'k' => $k, 'l' => $l];
66 $d = $e = 0xba53b411;
67 yield darray['a' => $a, 'b' => $b, 'c' => $c, 'd' => $d, 'e' => $e, 'f' => $f, 'g' => $g, 'h' => $h, 'i' => $i, 'j' => $j, 'k' => $k, 'l' => $l];
70 <<__EntryPoint>> function main(): void {
71 dumpgen(create());
72 dumpgen(unusedarg(new logger(), 5));
73 dumpgen(getargs(1, 2, 3, 4, 5));
74 $g = genthrow();
75 try {
76 $g->next();
77 } catch (Exception $e) {}
78 try {
79 $g->next();
80 } catch (Exception $e) {
81 var_dump($e->getMessage());
84 $g = manylocals();
85 $g->next();
86 var_dump($g->current());
87 $g->send(new stdclass);
88 var_dump($g->current());
89 $g->send($g);
90 var_dump($g->current());
91 $g->next();
92 var_dump($g->current());
93 var_dump($g->valid());