7 function __construct($b = 'foo') { $this->b
= $b; }
13 function __construct($b = 'foo') { $this->b
= $b; }
22 function __construct($str = 'foo') { $this->str
= $str; }
23 function __toString() { return $this->str
; }
26 class ToStringThrower
{
27 function __toString() { throw new Exception('sneaky'); }
30 class DateTime1
implements DateTimeInterface
{
31 public $timestamp = 0;
32 function __construct($timestamp) { $this->timestamp
= $timestamp; }
33 function getTimestamp() {
34 if ($this->timestamp
<= 0) {
35 throw new Exception('sneaky');
37 return $this->timestamp
;
39 function diff($dt, $absolute = null) {}
40 function format($format) {}
41 function getTimezone() {}
42 function getOffset() {}
45 class DateTime2
implements DateTimeInterface
{
46 function getTimestamp() { return 100; }
47 function diff($dt, $absolute = null) {}
48 function format($format) {}
49 function getTimezone() {}
50 function getOffset() {}
53 function test_pair($k1, $v1, $k2, $v2) {
54 echo "$k1 cmp $k2:\n";
56 echo (($v1 === $v2) ?
"T " : "F ");
57 } catch (Exception
$e) {
61 echo (($v1 !== $v2) ?
"T " : "F ");
62 } catch (Exception
$e) {
66 echo (($v1 < $v2) ?
"T " : "F ");
67 } catch (Exception
$e) {
71 echo (($v1 <= $v2) ?
"T " : "F ");
72 } catch (Exception
$e) {
76 echo (($v1 == $v2) ?
"T " : "F ");
77 } catch (Exception
$e) {
81 echo (($v1 != $v2) ?
"T " : "F ");
82 } catch (Exception
$e) {
86 echo (($v1 >= $v2) ?
"T " : "F ");
87 } catch (Exception
$e) {
91 echo (($v1 > $v2) ?
"T " : "F ");
92 } catch (Exception
$e) {
98 } catch (Exception
$e) {
111 $a6 = new A(new ToString
);
112 $a7 = new A(new ToString('bar'));
113 $a8 = new A(new ToStringThrower
);
115 $a10 = new A(new ToString('99'));
116 $a11 = new A(new DateTime1(1000));
117 $a12 = new A(new DateTime1(1000));
118 $a13= new A(new DateTime1(100));
119 $a14 = new A(new DateTime1(-1));
120 $a15 = new A(new DateTime2
);
121 $a16 = new A
; $a16->c
= 999;
129 $s2 = new ToString('BAZ');
130 $s3 = new ToString('99');
131 $s4 = new ToStringThrower
;
133 $t1 = new DateTime1(1000);
134 $t2 = new DateTime1(1000);
135 $t3 = new DateTime1(100);
136 $t4 = new DateTime1(-1);
139 $ao1 = new ArrayObject(array());
140 $ao2 = new ArrayObject(array(99));
141 $ao3 = new ArrayObject(array(99));
143 $xml = simplexml_load_string("<root />")->unknown
;
145 $v1 = Vector
{0, 1, 2, 3, 4};
146 $v2 = Vector
{0, 1, 2, 3, 4};
147 $v3 = Vector
{5, 6, 7, 8, 9};
149 $p1 = Pair
{'elem1', 'elem2'};
150 $p2 = Pair
{'elem1', 'elem2'};
151 $p3 = Pair
{'other1', 'other2'};
153 $clo1 = function () { return 0; };
154 $clo2 = function () { return 0; };
158 $arr3 = array('foo');
159 $arr4 = array('foo', 'bar');
160 $arr5 = array('foo', 'bar');
161 $arr6 = array('foo', 'baz');
162 $arr7 = array(new A
, new A
);
163 $arr8 = array(new A
, new A
);
164 $arr9 = array(new A
, new C
);
165 $arr10 = array(new ToString('foo'), new ToString('bar'));
166 $arr11 = array(new ToString('foo'), new ToStringThrower
);
167 $arr12 = array(array(1, 2), array(1, 2, 3));
168 $arr13 = array(array(1, 2), array(1, 2, 3));
169 $arr14 = array(array(1, 2), array(99));
170 $arr15 = array(Vector
{0, 1, 2, 3, 4}, Vector
{5, 6, 7, 8});
171 $arr16 = array(Vector
{0, 1, 2, 3, 4}, Vector
{5, 6, 7, 8});
172 $arr17 = array(1, NAN
);
173 $arr18 = array(1, NAN
);
174 $arr19 = array(NAN
, 1);
175 $arr20 = array(1, NAN
, 2);
176 $arr21 = array('key1' => 1, 'key2' => 2, 'key3' => 3);
177 $arr22 = array('key1' => 1, 'key2' => 2, 'key3' => 3);
178 $arr23 = array('key1' => 1, 'key2-other' => 2, 'key3' => 3);
179 $arr24 = array('key2' => 2, 'key3' => 3, 'key1' => 1);
180 $arr25 = array('baz', 'foo');
181 $arr26 = array('baz', new ToStringThrower
);
185 $vec3 = vec
[1, 2, 3];
186 $vec4 = vec
[1, 2, 4];
187 $vec5 = vec
[new ToString('foo')];
188 $vec6 = vec
[new ToStringThrower
];
191 $vec9 = vec
[4, 2, 1];
192 $vec10 = vec
[1, 2, 'value'];
193 $vec11 = vec
[1, 2, new ToStringThrower
];
196 $dict2 = dict
['a' => 0, 'b' => 1];
197 $dict3 = dict
['a' => 0, 'b' => 1, 'c' => 2];
198 $dict4 = dict
['a' => 0, 'b' => 1, 'c' => 3];
199 $dict5 = dict
['a' => 0, 'z' => 1, 'c' => 3];
200 $dict6 = dict
[0 => new ToString('foo')];
201 $dict7 = dict
[0 => new ToStringThrower
];
202 $dict8 = dict
[0 => new A
];
203 $dict9 = dict
[0 => new A
];
204 $dict10 = dict
['c' => 2, 'b' => 1, 'a' => 0];
205 $dict11 = dict
[100 => new ToStringThrower
];
212 $ks6 = keyset
[1, 2, 3];
213 $ks7 = keyset
[3, 2, 1];
214 $ks8 = keyset
['a', 'b', 'c'];
215 $ks9 = keyset
['c', 'b', 'a'];
216 $ks10 = keyset
[1, 2, 4];
217 $ks11 = keyset
['a', 'b', 'd'];
218 $ks12 = keyset
[100, 2, 3];
219 $ks13 = keyset
['z', 'b', 'c'];
221 $f1 = imagecreate(10, 10);
222 $f2 = imagecreate(10, 10);
223 $f3 = imagecreate(1, 1);
225 $arr = array('null' => null,
227 'false' => false, 'true' => true,
229 'int 0' => 0, 'int 99' => 99, 'int -1' => -1,
231 'float 0' => 0.0,'double 99' => (double)99,
232 'float 99' => 99.0, 'float -1' => -1.0,
233 'INF' => INF
, '-INF' => -INF
, 'NAN' => NAN
,
235 '""' => "", '"0"' => "0",
236 '"99"' => "99", '"-1"' => "-1", '"0.0"' => "0.0",
237 '"99.0"' => "99.0", '"-1.0"' => "-1.0",
238 '"foo"' => "foo", '"BAZ"' => "BAZ",
240 'array arr1' => $arr1, 'array arr2' => $arr2,
241 'array arr3' => $arr3, 'array arr4' => $arr4,
242 'array arr5' => $arr5, 'array arr6' => $arr6,
243 'array arr7' => $arr7, 'array arr8' => $arr8,
244 'array arr9' => $arr9, 'array arr10' => $arr10,
245 'array arr11' => $arr11, 'array arr12' => $arr12,
246 'array arr13' => $arr13, 'array arr14' => $arr14,
247 'array arr15' => $arr15, 'array arr16' => $arr16,
248 'array arr17' => $arr17, 'array arr18' => $arr18,
249 'array arr19' => $arr19, 'array arr20' => $arr20,
250 'array arr21' => $arr21, 'array arr22' => $arr22,
251 'array arr23' => $arr23, 'array arr24' => $arr24,
252 'array arr25' => $arr25, 'array arr26' => $arr26,
254 'vec vec1' => $vec1, 'vec vec2' => $vec2, 'vec vec3' => $vec3,
255 'vec vec4' => $vec4, 'vec vec5' => $vec5, 'vec vec6' => $vec6,
256 'vec vec7' => $vec7, 'vec vec8' => $vec8, 'vec vec9' => $vec9,
257 'vec vec10' => $vec10, 'vec vec11' => $vec11,
259 'dict dict1' => $dict1, 'dict dict2' => $dict2, 'dict dict3' => $dict3,
260 'dict dict4' => $dict4, 'dict dict5' => $dict5, 'dict dict6' => $dict6,
261 'dict dict7' => $dict7, 'dict dict8' => $dict8, 'dict dict9' => $dict9,
262 'dict dict10' => $dict10, 'dict dict11' => $dict11,
264 'keyset ks1' => $ks1, 'keyset ks2' => $ks2, 'keyset ks3' => $ks3,
265 'keyset ks4' => $ks4, 'keyset ks5' => $ks5, 'keyset ks6' => $ks6,
266 'keyset ks7' => $ks7, 'keyset ks8' => $ks8, 'keyset ks9' => $ks9,
267 'keyset ks10' => $ks10, 'keyset ks11' => $ks11, 'keyset ks12' => $ks12,
268 'keyset ks13' => $ks13,
270 'object a1' => $a1, 'object a2' => $a2, 'object a3' => $a3,
271 'object a4' => $a4, 'object a5' => $a5, 'object a6' => $a6,
272 'object a7' => $a7, 'object a8' => $a8, 'object a9' => $a9,
273 'object a10' => $a10, 'object a11' => $a11, 'object a12' => $a12,
274 'object a13' => $a13, 'object a14' => $a14, 'object a15' => $a15,
275 'object a16' => $a16, 'object a17' => $a17, 'object a18' => $a18,
276 'object b1' => $b1, 'object c1' => $c1, 'object s1' => $s1,
277 'object s2' => $s2, 'object s3' => $s3, 'object s4' => $s4,
278 'object t1' => $t1, 'object t2' => $t2, 'object t3' => $t3,
279 'object t4' => $t4, 'object t5' => $t5, 'object ao1' => $ao1,
280 'object ao2' => $ao2, 'object ao3' => $ao3, 'object xml' => $xml,
282 'vector v1' => $v1, 'vector v2' => $v2, 'vector v3' => $v3,
283 'pair p1' => $p1, 'pair p2' => $p2, 'pair p3' => $p3,
285 'closure clo1' => $clo1, 'closure clo2' => $clo2,
287 'resource f1' => $f1, 'resource f2' => $f2, 'resource f3' => $f3,
290 echo "same nsame lt lte eq neq gte gt cmp\n\n";
291 foreach ($arr as $k1 => $v1) {
292 foreach ($arr as $k2 => $v2) {
293 test_pair($k1, $v1, $k2, $v2);