xref: /PHP-7.2/Zend/tests/compare_002.phpt (revision 17ccbeec)
1--TEST--
2comparing different variables for identity
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) !== object(stdClass)#1 (0) {}
98int(1) !== object(stdClass)#2 (0) {}
99int(1) !== object(test)#3 (0) {}
100int(1) !== array(0) {}
101int(1) !== int(-2147483648)
102int(1) !== string(11) "-2147483648"
103float(2.5) !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
104float(2.5) !== string(0) ""
105float(2.5) !== int(1)
106float(2.5) === float(2.5)
107float(2.5) !== int(0)
108float(2.5) !== string(6) "string"
109float(2.5) !== string(3) "123"
110float(2.5) !== string(3) "2.5"
111float(2.5) !== NULL
112float(2.5) !== bool(true)
113float(2.5) !== bool(false)
114float(2.5) !== object(stdClass)#1 (0) {}
115float(2.5) !== object(stdClass)#2 (0) {}
116float(2.5) !== object(test)#3 (0) {}
117float(2.5) !== array(0) {}
118float(2.5) !== int(-2147483648)
119float(2.5) !== string(11) "-2147483648"
120int(0) !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
121int(0) !== string(0) ""
122int(0) !== int(1)
123int(0) !== float(2.5)
124int(0) === int(0)
125int(0) !== string(6) "string"
126int(0) !== string(3) "123"
127int(0) !== string(3) "2.5"
128int(0) !== NULL
129int(0) !== bool(true)
130int(0) !== bool(false)
131int(0) !== object(stdClass)#1 (0) {}
132int(0) !== object(stdClass)#2 (0) {}
133int(0) !== object(test)#3 (0) {}
134int(0) !== array(0) {}
135int(0) !== int(-2147483648)
136int(0) !== string(11) "-2147483648"
137string(6) "string" !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
138string(6) "string" !== string(0) ""
139string(6) "string" !== int(1)
140string(6) "string" !== float(2.5)
141string(6) "string" !== int(0)
142string(6) "string" === string(6) "string"
143string(6) "string" !== string(3) "123"
144string(6) "string" !== string(3) "2.5"
145string(6) "string" !== NULL
146string(6) "string" !== bool(true)
147string(6) "string" !== bool(false)
148string(6) "string" !== object(stdClass)#1 (0) {}
149string(6) "string" !== object(stdClass)#2 (0) {}
150string(6) "string" !== object(test)#3 (0) {}
151string(6) "string" !== array(0) {}
152string(6) "string" !== int(-2147483648)
153string(6) "string" !== string(11) "-2147483648"
154string(3) "123" !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
155string(3) "123" !== string(0) ""
156string(3) "123" !== int(1)
157string(3) "123" !== float(2.5)
158string(3) "123" !== int(0)
159string(3) "123" !== string(6) "string"
160string(3) "123" === string(3) "123"
161string(3) "123" !== string(3) "2.5"
162string(3) "123" !== NULL
163string(3) "123" !== bool(true)
164string(3) "123" !== bool(false)
165string(3) "123" !== object(stdClass)#1 (0) {}
166string(3) "123" !== object(stdClass)#2 (0) {}
167string(3) "123" !== object(test)#3 (0) {}
168string(3) "123" !== array(0) {}
169string(3) "123" !== int(-2147483648)
170string(3) "123" !== string(11) "-2147483648"
171string(3) "2.5" !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
172string(3) "2.5" !== string(0) ""
173string(3) "2.5" !== int(1)
174string(3) "2.5" !== float(2.5)
175string(3) "2.5" !== int(0)
176string(3) "2.5" !== string(6) "string"
177string(3) "2.5" !== string(3) "123"
178string(3) "2.5" === string(3) "2.5"
179string(3) "2.5" !== NULL
180string(3) "2.5" !== bool(true)
181string(3) "2.5" !== bool(false)
182string(3) "2.5" !== object(stdClass)#1 (0) {}
183string(3) "2.5" !== object(stdClass)#2 (0) {}
184string(3) "2.5" !== object(test)#3 (0) {}
185string(3) "2.5" !== array(0) {}
186string(3) "2.5" !== int(-2147483648)
187string(3) "2.5" !== string(11) "-2147483648"
188NULL !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
189NULL !== string(0) ""
190NULL !== int(1)
191NULL !== float(2.5)
192NULL !== int(0)
193NULL !== string(6) "string"
194NULL !== string(3) "123"
195NULL !== string(3) "2.5"
196NULL === NULL
197NULL !== bool(true)
198NULL !== bool(false)
199NULL !== object(stdClass)#1 (0) {}
200NULL !== object(stdClass)#2 (0) {}
201NULL !== object(test)#3 (0) {}
202NULL !== array(0) {}
203NULL !== int(-2147483648)
204NULL !== string(11) "-2147483648"
205bool(true) !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
206bool(true) !== string(0) ""
207bool(true) !== int(1)
208bool(true) !== float(2.5)
209bool(true) !== int(0)
210bool(true) !== string(6) "string"
211bool(true) !== string(3) "123"
212bool(true) !== string(3) "2.5"
213bool(true) !== NULL
214bool(true) === bool(true)
215bool(true) !== bool(false)
216bool(true) !== object(stdClass)#1 (0) {}
217bool(true) !== object(stdClass)#2 (0) {}
218bool(true) !== object(test)#3 (0) {}
219bool(true) !== array(0) {}
220bool(true) !== int(-2147483648)
221bool(true) !== string(11) "-2147483648"
222bool(false) !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
223bool(false) !== string(0) ""
224bool(false) !== int(1)
225bool(false) !== float(2.5)
226bool(false) !== int(0)
227bool(false) !== string(6) "string"
228bool(false) !== string(3) "123"
229bool(false) !== string(3) "2.5"
230bool(false) !== NULL
231bool(false) !== bool(true)
232bool(false) === bool(false)
233bool(false) !== object(stdClass)#1 (0) {}
234bool(false) !== object(stdClass)#2 (0) {}
235bool(false) !== object(test)#3 (0) {}
236bool(false) !== array(0) {}
237bool(false) !== int(-2147483648)
238bool(false) !== string(11) "-2147483648"
239object(stdClass)#1 (0) {} !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
240object(stdClass)#1 (0) {} !== string(0) ""
241object(stdClass)#1 (0) {} !== int(1)
242object(stdClass)#1 (0) {} !== float(2.5)
243object(stdClass)#1 (0) {} !== int(0)
244object(stdClass)#1 (0) {} !== string(6) "string"
245object(stdClass)#1 (0) {} !== string(3) "123"
246object(stdClass)#1 (0) {} !== string(3) "2.5"
247object(stdClass)#1 (0) {} !== NULL
248object(stdClass)#1 (0) {} !== bool(true)
249object(stdClass)#1 (0) {} !== bool(false)
250object(stdClass)#1 (0) {} === object(stdClass)#1 (0) {}
251object(stdClass)#1 (0) {} !== object(stdClass)#2 (0) {}
252object(stdClass)#1 (0) {} !== object(test)#3 (0) {}
253object(stdClass)#1 (0) {} !== array(0) {}
254object(stdClass)#1 (0) {} !== int(-2147483648)
255object(stdClass)#1 (0) {} !== string(11) "-2147483648"
256object(stdClass)#2 (0) {} !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
257object(stdClass)#2 (0) {} !== string(0) ""
258object(stdClass)#2 (0) {} !== int(1)
259object(stdClass)#2 (0) {} !== float(2.5)
260object(stdClass)#2 (0) {} !== int(0)
261object(stdClass)#2 (0) {} !== string(6) "string"
262object(stdClass)#2 (0) {} !== string(3) "123"
263object(stdClass)#2 (0) {} !== string(3) "2.5"
264object(stdClass)#2 (0) {} !== NULL
265object(stdClass)#2 (0) {} !== bool(true)
266object(stdClass)#2 (0) {} !== bool(false)
267object(stdClass)#2 (0) {} !== object(stdClass)#1 (0) {}
268object(stdClass)#2 (0) {} === object(stdClass)#2 (0) {}
269object(stdClass)#2 (0) {} !== object(test)#3 (0) {}
270object(stdClass)#2 (0) {} !== array(0) {}
271object(stdClass)#2 (0) {} !== int(-2147483648)
272object(stdClass)#2 (0) {} !== string(11) "-2147483648"
273object(test)#3 (0) {} !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
274object(test)#3 (0) {} !== string(0) ""
275object(test)#3 (0) {} !== int(1)
276object(test)#3 (0) {} !== float(2.5)
277object(test)#3 (0) {} !== int(0)
278object(test)#3 (0) {} !== string(6) "string"
279object(test)#3 (0) {} !== string(3) "123"
280object(test)#3 (0) {} !== string(3) "2.5"
281object(test)#3 (0) {} !== NULL
282object(test)#3 (0) {} !== bool(true)
283object(test)#3 (0) {} !== bool(false)
284object(test)#3 (0) {} !== object(stdClass)#1 (0) {}
285object(test)#3 (0) {} !== object(stdClass)#2 (0) {}
286object(test)#3 (0) {} === object(test)#3 (0) {}
287object(test)#3 (0) {} !== array(0) {}
288object(test)#3 (0) {} !== int(-2147483648)
289object(test)#3 (0) {} !== string(11) "-2147483648"
290array(0) {} !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
291array(0) {} !== string(0) ""
292array(0) {} !== int(1)
293array(0) {} !== float(2.5)
294array(0) {} !== int(0)
295array(0) {} !== string(6) "string"
296array(0) {} !== string(3) "123"
297array(0) {} !== string(3) "2.5"
298array(0) {} !== NULL
299array(0) {} !== bool(true)
300array(0) {} !== bool(false)
301array(0) {} !== object(stdClass)#1 (0) {}
302array(0) {} !== object(stdClass)#2 (0) {}
303array(0) {} !== object(test)#3 (0) {}
304array(0) {} === array(0) {}
305array(0) {} !== int(-2147483648)
306array(0) {} !== string(11) "-2147483648"
307int(-2147483648) !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
308int(-2147483648) !== string(0) ""
309int(-2147483648) !== int(1)
310int(-2147483648) !== float(2.5)
311int(-2147483648) !== int(0)
312int(-2147483648) !== string(6) "string"
313int(-2147483648) !== string(3) "123"
314int(-2147483648) !== string(3) "2.5"
315int(-2147483648) !== NULL
316int(-2147483648) !== bool(true)
317int(-2147483648) !== bool(false)
318int(-2147483648) !== object(stdClass)#1 (0) {}
319int(-2147483648) !== object(stdClass)#2 (0) {}
320int(-2147483648) !== object(test)#3 (0) {}
321int(-2147483648) !== array(0) {}
322int(-2147483648) === int(-2147483648)
323int(-2147483648) !== string(11) "-2147483648"
324string(11) "-2147483648" !== array(3) {  [0]=>  int(1)  [1]=>  int(2)  [2]=>  int(3)}
325string(11) "-2147483648" !== string(0) ""
326string(11) "-2147483648" !== int(1)
327string(11) "-2147483648" !== float(2.5)
328string(11) "-2147483648" !== int(0)
329string(11) "-2147483648" !== string(6) "string"
330string(11) "-2147483648" !== string(3) "123"
331string(11) "-2147483648" !== string(3) "2.5"
332string(11) "-2147483648" !== NULL
333string(11) "-2147483648" !== bool(true)
334string(11) "-2147483648" !== bool(false)
335string(11) "-2147483648" !== object(stdClass)#1 (0) {}
336string(11) "-2147483648" !== object(stdClass)#2 (0) {}
337string(11) "-2147483648" !== object(test)#3 (0) {}
338string(11) "-2147483648" !== array(0) {}
339string(11) "-2147483648" !== int(-2147483648)
340string(11) "-2147483648" === string(11) "-2147483648"
341Done
342