add bitset operations and tests
[hiphop-php.git] / hphp / test / slow / apc_objects.php
blob52be14694b8683d0ca519166721ce5900a7ff301
1 <?hh
3 $s = strtolower('heLLo');
5 class C {
6 public $x = 3;
7 public $f = 'hi';
10 class B {
11 public $f;
14 function apcOps($key, $val) {
15 apc_store($key, $val);
16 // need to fetch the value twice because under common
17 // config settings object are serialized on first store
18 // and APCObject (APCCollection) are created on second
19 // fetch
20 var_dump(apc_fetch($key));
21 var_dump(apc_fetch($key));
24 echo "**** Object instance with simple properties\n";
25 $o = new C;
26 apcOps('key', $o);
28 echo "**** Vector containing object reference\n";
29 $c = Vector{1, 2, $o};
30 apcOps('key', $c);
31 echo "modify previous instance from APC\n";
32 $apcObj = apc_fetch('key');
33 $apcObj[] = 'hi';
34 $apcObj[0] = 100;
35 $opcObj = null;
36 var_dump('MUTATED', $apcObj);
37 var_dump(apc_fetch('key'));
39 echo "**** Vector containing non-refcounted values\n";
40 $c = Vector{1, 'hello'};
41 apcOps('key', $c);
42 echo "modify previous instance from APC\n";
43 $apcObj = apc_fetch('key');
44 $apcObj[] = 'hi';
45 $apcObj[0] = 100;
46 $opcObj = null;
47 var_dump('MUTATED', $apcObj);
48 var_dump(apc_fetch('key'));
50 echo "**** Vector containing simple values\n";
51 $c = Vector{true, $s};
52 apcOps('key', $c);
53 echo "modify previous instance from APC\n";
54 $apcObj = apc_fetch('key');
55 $apcObj[] = 'hi';
56 $apcObj[0] = 100;
57 $opcObj = null;
58 var_dump('MUTATED', $apcObj);
59 var_dump(apc_fetch('key'));
61 echo "**** Map containing non-refcounted values\n";
62 $m = Map{'a' => 'b', 'c' => 'd'};
63 apcOps('key', $m);
64 echo "modify previous instance from APC\n";
65 $apcObj = apc_fetch('key');
66 $apcObj['one'] = 'hi';
67 $apcObj['a'] = 100;
68 $opcObj = null;
69 var_dump('MUTATED', $apcObj);
70 var_dump(apc_fetch('key'));
72 echo "**** Map containing itself\n";
73 $m = Map{'a' => 'b', 'c' => $m};
74 apcOps('key', $m);
75 echo "modify previous instance from APC\n";
76 $apcObj = apc_fetch('key');
77 $apcObj['one'] = 'hi';
78 $apcObj['a'] = 100;
79 $opcObj = null;
80 var_dump('MUTATED', $apcObj);
81 var_dump(apc_fetch('key'));
83 echo "**** Map containing a vector\n";
84 $m = Map{'a' => 'b', 'c' => $c};
85 apcOps('key', $m);
86 echo "modify previous instance from APC\n";
87 $apcObj = apc_fetch('key');
88 $apcObj['one'] = 'hi';
89 $apcObj['a'] = 100;
90 $opcObj = null;
91 var_dump('MUTATED', $apcObj);
92 var_dump(apc_fetch('key'));
94 echo "**** Immutable Vector instance\n";
95 $c = ImmVector{1, 'hello'};
96 apcOps('key', $c);
98 echo "**** Immutable Map instance\n";
99 $m = ImmMap{'a' => 'b', 'c' => 'd'};
100 apcOps('key', $m);
102 echo "**** Object instance containg itself\n";
103 $o = new C;
104 $o->x = $o;
105 apcOps('key', $o);
107 echo "**** Object instance containg itself 2\n";
108 $o = new C;
109 $o->x = new B;
110 $o->x->f = $o;
111 apcOps('key', $o);
113 echo "**** Object instance containg itself 3\n";
114 $o = new C;
115 $o->x = new B;
116 $o->x->f = Vector{};
117 $o->x->f[] = $o;
118 apcOps('key', $o);
120 echo "**** Object instance containg itself 4\n";
121 $o = new C;
122 $o->x = new B;
123 $o->x->f = Vector{};
124 $o->x->f[] = $o->x;
125 apcOps('key', $o);
127 echo "**** Object instance containg itself 5\n";
128 $o = new C;
129 $o->x = new B;
130 $o->x->f = Vector{};
131 $o->x->f[] = new B;
132 apcOps('key', $o);
134 echo "**** Object instance containg Vector instace with simple values\n";
135 $o = new C;
136 $o->x = new B;
137 $o->x->f = Vector{};
138 $o->x->f[] = 10;
139 $o->x->f[] = 'hi';
140 $o->x->f[] = strtolower('heLLo');
141 apcOps('key', $o);
143 echo "**** Object instance containg collections instaces\n";
144 $o = new C;
145 $o->x = new B;
146 $o->x->f = Map{};
147 $o->x->f['k'] = 10;
148 $o->x->f['k1'] = 'hi';
149 $o->x->f['k2'] = Vector{};
150 $o->x->f['k2'][] = 100;
151 $o->x->f['k2'][] = 'hello';
152 apcOps('key', $o);
154 echo "**** Set instance\n";
155 $s = Set{ 1, 'hi', 4, $s};
156 apcOps('key', $s);
158 echo "**** Set instance with int-like strings\n";
159 $s = Set{ 123, '123'};
160 apcOps('key', $s);
162 echo "**** Make sure delete is ok\n";
163 apc_delete('key');