xref: /PHP-8.3/Zend/tests/compare_001.phpt (revision acbf7802)
1--TEST--
2comparing different variables for equality
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?>
5--FILE--
6<?php
7
8class test {
9}
10
11$a = array(
12    array(1,2,3),
13    "",
14    1,
15    2.5,
16    0,
17    "string",
18    "123",
19    "2.5",
20    NULL,
21    true,
22    false,
23    new stdclass,
24    new stdclass,
25    new test,
26    array(),
27    -PHP_INT_MAX-1,
28    (string)(-PHP_INT_MAX-1),
29);
30
31$var_cnt = count($a);
32
33function my_dump($var) {
34    ob_start();
35    var_dump($var);
36    $buf = ob_get_clean();
37    echo str_replace("\n", "", $buf);
38}
39
40foreach($a as $var) {
41    for ($i = 0; $i < $var_cnt; $i++) {
42        my_dump($var);
43        echo ($var == $a[$i]) ? " == " : " != ";
44        my_dump($a[$i]);
45        echo "\n";
46    }
47}
48
49echo "Done\n";
50?>
51--EXPECTF--
52array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} == array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
53array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != string(0) ""
54array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != int(1)
55array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != float(2.5)
56array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != int(0)
57array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != string(6) "string"
58array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != string(3) "123"
59array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != string(3) "2.5"
60array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != NULL
61array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} == bool(true)
62array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != bool(false)
63array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != object(stdClass)#1 (0) {}
64array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != object(stdClass)#2 (0) {}
65array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != object(test)#3 (0) {}
66array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != array(0) {}
67array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != int(-2147483648)
68array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)} != string(11) "-2147483648"
69string(0) "" != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
70string(0) "" == string(0) ""
71string(0) "" != int(1)
72string(0) "" != float(2.5)
73string(0) "" != int(0)
74string(0) "" != string(6) "string"
75string(0) "" != string(3) "123"
76string(0) "" != string(3) "2.5"
77string(0) "" == NULL
78string(0) "" != bool(true)
79string(0) "" == bool(false)
80string(0) "" != object(stdClass)#1 (0) {}
81string(0) "" != object(stdClass)#2 (0) {}
82string(0) "" != object(test)#3 (0) {}
83string(0) "" != array(0) {}
84string(0) "" != int(-2147483648)
85string(0) "" != string(11) "-2147483648"
86int(1) != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
87int(1) != string(0) ""
88int(1) == int(1)
89int(1) != float(2.5)
90int(1) != int(0)
91int(1) != string(6) "string"
92int(1) != string(3) "123"
93int(1) != string(3) "2.5"
94int(1) != NULL
95int(1) == bool(true)
96int(1) != bool(false)
97int(1)
98Notice: Object of class stdClass could not be converted to int in %s on line %d
99 == object(stdClass)#1 (0) {}
100int(1)
101Notice: Object of class stdClass could not be converted to int in %s on line %d
102 == object(stdClass)#2 (0) {}
103int(1)
104Notice: Object of class test could not be converted to int in %s on line %d
105 == object(test)#3 (0) {}
106int(1) != array(0) {}
107int(1) != int(-2147483648)
108int(1) != string(11) "-2147483648"
109float(2.5) != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
110float(2.5) != string(0) ""
111float(2.5) != int(1)
112float(2.5) == float(2.5)
113float(2.5) != int(0)
114float(2.5) != string(6) "string"
115float(2.5) != string(3) "123"
116float(2.5) == string(3) "2.5"
117float(2.5) != NULL
118float(2.5) == bool(true)
119float(2.5) != bool(false)
120float(2.5)
121Notice: Object of class stdClass could not be converted to float in %s on line %d
122 != object(stdClass)#1 (0) {}
123float(2.5)
124Notice: Object of class stdClass could not be converted to float in %s on line %d
125 != object(stdClass)#2 (0) {}
126float(2.5)
127Notice: Object of class test could not be converted to float in %s on line %d
128 != object(test)#3 (0) {}
129float(2.5) != array(0) {}
130float(2.5) != int(-2147483648)
131float(2.5) != string(11) "-2147483648"
132int(0) != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
133int(0) != string(0) ""
134int(0) != int(1)
135int(0) != float(2.5)
136int(0) == int(0)
137int(0) != string(6) "string"
138int(0) != string(3) "123"
139int(0) != string(3) "2.5"
140int(0) == NULL
141int(0) != bool(true)
142int(0) == bool(false)
143int(0)
144Notice: Object of class stdClass could not be converted to int in %s on line %d
145 != object(stdClass)#1 (0) {}
146int(0)
147Notice: Object of class stdClass could not be converted to int in %s on line %d
148 != object(stdClass)#2 (0) {}
149int(0)
150Notice: Object of class test could not be converted to int in %s on line %d
151 != object(test)#3 (0) {}
152int(0) != array(0) {}
153int(0) != int(-2147483648)
154int(0) != string(11) "-2147483648"
155string(6) "string" != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
156string(6) "string" != string(0) ""
157string(6) "string" != int(1)
158string(6) "string" != float(2.5)
159string(6) "string" != int(0)
160string(6) "string" == string(6) "string"
161string(6) "string" != string(3) "123"
162string(6) "string" != string(3) "2.5"
163string(6) "string" != NULL
164string(6) "string" == bool(true)
165string(6) "string" != bool(false)
166string(6) "string" != object(stdClass)#1 (0) {}
167string(6) "string" != object(stdClass)#2 (0) {}
168string(6) "string" != object(test)#3 (0) {}
169string(6) "string" != array(0) {}
170string(6) "string" != int(-2147483648)
171string(6) "string" != string(11) "-2147483648"
172string(3) "123" != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
173string(3) "123" != string(0) ""
174string(3) "123" != int(1)
175string(3) "123" != float(2.5)
176string(3) "123" != int(0)
177string(3) "123" != string(6) "string"
178string(3) "123" == string(3) "123"
179string(3) "123" != string(3) "2.5"
180string(3) "123" != NULL
181string(3) "123" == bool(true)
182string(3) "123" != bool(false)
183string(3) "123" != object(stdClass)#1 (0) {}
184string(3) "123" != object(stdClass)#2 (0) {}
185string(3) "123" != object(test)#3 (0) {}
186string(3) "123" != array(0) {}
187string(3) "123" != int(-2147483648)
188string(3) "123" != string(11) "-2147483648"
189string(3) "2.5" != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
190string(3) "2.5" != string(0) ""
191string(3) "2.5" != int(1)
192string(3) "2.5" == float(2.5)
193string(3) "2.5" != int(0)
194string(3) "2.5" != string(6) "string"
195string(3) "2.5" != string(3) "123"
196string(3) "2.5" == string(3) "2.5"
197string(3) "2.5" != NULL
198string(3) "2.5" == bool(true)
199string(3) "2.5" != bool(false)
200string(3) "2.5" != object(stdClass)#1 (0) {}
201string(3) "2.5" != object(stdClass)#2 (0) {}
202string(3) "2.5" != object(test)#3 (0) {}
203string(3) "2.5" != array(0) {}
204string(3) "2.5" != int(-2147483648)
205string(3) "2.5" != string(11) "-2147483648"
206NULL != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
207NULL == string(0) ""
208NULL != int(1)
209NULL != float(2.5)
210NULL == int(0)
211NULL != string(6) "string"
212NULL != string(3) "123"
213NULL != string(3) "2.5"
214NULL == NULL
215NULL != bool(true)
216NULL == bool(false)
217NULL != object(stdClass)#1 (0) {}
218NULL != object(stdClass)#2 (0) {}
219NULL != object(test)#3 (0) {}
220NULL == array(0) {}
221NULL != int(-2147483648)
222NULL != string(11) "-2147483648"
223bool(true) == array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
224bool(true) != string(0) ""
225bool(true) == int(1)
226bool(true) == float(2.5)
227bool(true) != int(0)
228bool(true) == string(6) "string"
229bool(true) == string(3) "123"
230bool(true) == string(3) "2.5"
231bool(true) != NULL
232bool(true) == bool(true)
233bool(true) != bool(false)
234bool(true) == object(stdClass)#1 (0) {}
235bool(true) == object(stdClass)#2 (0) {}
236bool(true) == object(test)#3 (0) {}
237bool(true) != array(0) {}
238bool(true) == int(-2147483648)
239bool(true) == string(11) "-2147483648"
240bool(false) != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
241bool(false) == string(0) ""
242bool(false) != int(1)
243bool(false) != float(2.5)
244bool(false) == int(0)
245bool(false) != string(6) "string"
246bool(false) != string(3) "123"
247bool(false) != string(3) "2.5"
248bool(false) == NULL
249bool(false) != bool(true)
250bool(false) == bool(false)
251bool(false) != object(stdClass)#1 (0) {}
252bool(false) != object(stdClass)#2 (0) {}
253bool(false) != object(test)#3 (0) {}
254bool(false) == array(0) {}
255bool(false) != int(-2147483648)
256bool(false) != string(11) "-2147483648"
257object(stdClass)#1 (0) {} != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
258object(stdClass)#1 (0) {} != string(0) ""
259object(stdClass)#1 (0) {}
260Notice: Object of class stdClass could not be converted to int in %s on line %d
261 == int(1)
262object(stdClass)#1 (0) {}
263Notice: Object of class stdClass could not be converted to float in %s on line %d
264 != float(2.5)
265object(stdClass)#1 (0) {}
266Notice: Object of class stdClass could not be converted to int in %s on line %d
267 != int(0)
268object(stdClass)#1 (0) {} != string(6) "string"
269object(stdClass)#1 (0) {} != string(3) "123"
270object(stdClass)#1 (0) {} != string(3) "2.5"
271object(stdClass)#1 (0) {} != NULL
272object(stdClass)#1 (0) {} == bool(true)
273object(stdClass)#1 (0) {} != bool(false)
274object(stdClass)#1 (0) {} == object(stdClass)#1 (0) {}
275object(stdClass)#1 (0) {} == object(stdClass)#2 (0) {}
276object(stdClass)#1 (0) {} != object(test)#3 (0) {}
277object(stdClass)#1 (0) {} != array(0) {}
278object(stdClass)#1 (0) {}
279Notice: Object of class stdClass could not be converted to int in %s on line %d
280 != int(-2147483648)
281object(stdClass)#1 (0) {} != string(11) "-2147483648"
282object(stdClass)#2 (0) {} != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
283object(stdClass)#2 (0) {} != string(0) ""
284object(stdClass)#2 (0) {}
285Notice: Object of class stdClass could not be converted to int in %s on line %d
286 == int(1)
287object(stdClass)#2 (0) {}
288Notice: Object of class stdClass could not be converted to float in %s on line %d
289 != float(2.5)
290object(stdClass)#2 (0) {}
291Notice: Object of class stdClass could not be converted to int in %s on line %d
292 != int(0)
293object(stdClass)#2 (0) {} != string(6) "string"
294object(stdClass)#2 (0) {} != string(3) "123"
295object(stdClass)#2 (0) {} != string(3) "2.5"
296object(stdClass)#2 (0) {} != NULL
297object(stdClass)#2 (0) {} == bool(true)
298object(stdClass)#2 (0) {} != bool(false)
299object(stdClass)#2 (0) {} == object(stdClass)#1 (0) {}
300object(stdClass)#2 (0) {} == object(stdClass)#2 (0) {}
301object(stdClass)#2 (0) {} != object(test)#3 (0) {}
302object(stdClass)#2 (0) {} != array(0) {}
303object(stdClass)#2 (0) {}
304Notice: Object of class stdClass could not be converted to int in %s on line %d
305 != int(-2147483648)
306object(stdClass)#2 (0) {} != string(11) "-2147483648"
307object(test)#3 (0) {} != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
308object(test)#3 (0) {} != string(0) ""
309object(test)#3 (0) {}
310Notice: Object of class test could not be converted to int in %s on line %d
311 == int(1)
312object(test)#3 (0) {}
313Notice: Object of class test could not be converted to float in %s on line %d
314 != float(2.5)
315object(test)#3 (0) {}
316Notice: Object of class test could not be converted to int in %s on line %d
317 != int(0)
318object(test)#3 (0) {} != string(6) "string"
319object(test)#3 (0) {} != string(3) "123"
320object(test)#3 (0) {} != string(3) "2.5"
321object(test)#3 (0) {} != NULL
322object(test)#3 (0) {} == bool(true)
323object(test)#3 (0) {} != bool(false)
324object(test)#3 (0) {} != object(stdClass)#1 (0) {}
325object(test)#3 (0) {} != object(stdClass)#2 (0) {}
326object(test)#3 (0) {} == object(test)#3 (0) {}
327object(test)#3 (0) {} != array(0) {}
328object(test)#3 (0) {}
329Notice: Object of class test could not be converted to int in %s on line %d
330 != int(-2147483648)
331object(test)#3 (0) {} != string(11) "-2147483648"
332array(0) {} != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
333array(0) {} != string(0) ""
334array(0) {} != int(1)
335array(0) {} != float(2.5)
336array(0) {} != int(0)
337array(0) {} != string(6) "string"
338array(0) {} != string(3) "123"
339array(0) {} != string(3) "2.5"
340array(0) {} == NULL
341array(0) {} != bool(true)
342array(0) {} == bool(false)
343array(0) {} != object(stdClass)#1 (0) {}
344array(0) {} != object(stdClass)#2 (0) {}
345array(0) {} != object(test)#3 (0) {}
346array(0) {} == array(0) {}
347array(0) {} != int(-2147483648)
348array(0) {} != string(11) "-2147483648"
349int(-2147483648) != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
350int(-2147483648) != string(0) ""
351int(-2147483648) != int(1)
352int(-2147483648) != float(2.5)
353int(-2147483648) != int(0)
354int(-2147483648) != string(6) "string"
355int(-2147483648) != string(3) "123"
356int(-2147483648) != string(3) "2.5"
357int(-2147483648) != NULL
358int(-2147483648) == bool(true)
359int(-2147483648) != bool(false)
360int(-2147483648)
361Notice: Object of class stdClass could not be converted to int in %s on line %d
362 != object(stdClass)#1 (0) {}
363int(-2147483648)
364Notice: Object of class stdClass could not be converted to int in %s on line %d
365 != object(stdClass)#2 (0) {}
366int(-2147483648)
367Notice: Object of class test could not be converted to int in %s on line %d
368 != object(test)#3 (0) {}
369int(-2147483648) != array(0) {}
370int(-2147483648) == int(-2147483648)
371int(-2147483648) == string(11) "-2147483648"
372string(11) "-2147483648" != array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
373string(11) "-2147483648" != string(0) ""
374string(11) "-2147483648" != int(1)
375string(11) "-2147483648" != float(2.5)
376string(11) "-2147483648" != int(0)
377string(11) "-2147483648" != string(6) "string"
378string(11) "-2147483648" != string(3) "123"
379string(11) "-2147483648" != string(3) "2.5"
380string(11) "-2147483648" != NULL
381string(11) "-2147483648" == bool(true)
382string(11) "-2147483648" != bool(false)
383string(11) "-2147483648" != object(stdClass)#1 (0) {}
384string(11) "-2147483648" != object(stdClass)#2 (0) {}
385string(11) "-2147483648" != object(test)#3 (0) {}
386string(11) "-2147483648" != array(0) {}
387string(11) "-2147483648" == int(-2147483648)
388string(11) "-2147483648" == string(11) "-2147483648"
389Done
390