xref: /PHP-7.0/ext/gmp/tests/overloading.phpt (revision f10d194c)
1--TEST--
2GMP operator overloading
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8$a = gmp_init(42);
9$b = gmp_init(17);
10
11var_dump($a + $b);
12var_dump($a + 17);
13var_dump(42 + $b);
14
15var_dump($a - $b);
16var_dump($a - 17);
17var_dump(42 - $b);
18
19var_dump($a * $b);
20var_dump($a * 17);
21var_dump(42 * $b);
22
23var_dump($a / $b);
24var_dump($a / 17);
25var_dump(42 / $b);
26var_dump($a / 0);
27
28var_dump($a % $b);
29var_dump($a % 17);
30var_dump(42 % $b);
31var_dump($a % 0);
32
33var_dump($a ** $b);
34var_dump($a ** 17);
35var_dump(42 ** $b);
36
37var_dump($a | $b);
38var_dump($a | 17);
39var_dump(42 | $b);
40
41var_dump($a & $b);
42var_dump($a & 17);
43var_dump(42 & $b);
44
45var_dump($a ^ $b);
46var_dump($a ^ 17);
47var_dump(42 ^ $b);
48
49var_dump($a << $b);
50var_dump($a << 17);
51var_dump(42 << $b);
52
53var_dump($a >> 2);
54var_dump(-$a >> 2);
55
56var_dump($a << -1);
57var_dump($a >> -1);
58
59var_dump(~$a);
60var_dump(-$a);
61var_dump(+$a);
62
63var_dump($a == $b);
64var_dump($a != $b);
65var_dump($a < $b);
66var_dump($a <= $b);
67var_dump($a > $b);
68var_dump($a >= $b);
69
70var_dump($a == $a);
71var_dump($a != $a);
72
73var_dump($a == 42);
74var_dump($a != 42);
75var_dump($a < 42);
76var_dump($a <= 42);
77var_dump($a > 42);
78var_dump($a >= 42);
79
80var_dump($a == new stdClass);
81
82$a += 1;
83var_dump($a);
84$a -= 1;
85var_dump($a);
86
87var_dump(++$a);
88var_dump($a++);
89var_dump($a);
90
91var_dump(--$a);
92var_dump($a--);
93var_dump($a);
94
95// Test operator that was not overloaded
96
97var_dump($a . $b);
98var_dump($a . '17');
99var_dump('42' . $b);
100
101$a .= '17';
102var_dump($a);
103
104?>
105--EXPECTF--
106object(GMP)#%d (1) {
107  ["num"]=>
108  string(2) "59"
109}
110object(GMP)#%d (1) {
111  ["num"]=>
112  string(2) "59"
113}
114object(GMP)#%d (1) {
115  ["num"]=>
116  string(2) "59"
117}
118object(GMP)#%d (1) {
119  ["num"]=>
120  string(2) "25"
121}
122object(GMP)#%d (1) {
123  ["num"]=>
124  string(2) "25"
125}
126object(GMP)#%d (1) {
127  ["num"]=>
128  string(2) "25"
129}
130object(GMP)#%d (1) {
131  ["num"]=>
132  string(3) "714"
133}
134object(GMP)#%d (1) {
135  ["num"]=>
136  string(3) "714"
137}
138object(GMP)#%d (1) {
139  ["num"]=>
140  string(3) "714"
141}
142object(GMP)#%d (1) {
143  ["num"]=>
144  string(1) "2"
145}
146object(GMP)#%d (1) {
147  ["num"]=>
148  string(1) "2"
149}
150object(GMP)#%d (1) {
151  ["num"]=>
152  string(1) "2"
153}
154
155Warning: main(): Zero operand not allowed in %s on line %d
156bool(false)
157object(GMP)#%d (1) {
158  ["num"]=>
159  string(1) "8"
160}
161object(GMP)#%d (1) {
162  ["num"]=>
163  string(1) "8"
164}
165object(GMP)#%d (1) {
166  ["num"]=>
167  string(1) "8"
168}
169
170Warning: main(): Zero operand not allowed in %s on line %d
171bool(false)
172object(GMP)#%d (1) {
173  ["num"]=>
174  string(28) "3937657486715347520027492352"
175}
176object(GMP)#%d (1) {
177  ["num"]=>
178  string(28) "3937657486715347520027492352"
179}
180object(GMP)#%d (1) {
181  ["num"]=>
182  string(28) "3937657486715347520027492352"
183}
184object(GMP)#%d (1) {
185  ["num"]=>
186  string(2) "59"
187}
188object(GMP)#%d (1) {
189  ["num"]=>
190  string(2) "59"
191}
192object(GMP)#%d (1) {
193  ["num"]=>
194  string(2) "59"
195}
196object(GMP)#%d (1) {
197  ["num"]=>
198  string(1) "0"
199}
200object(GMP)#%d (1) {
201  ["num"]=>
202  string(1) "0"
203}
204object(GMP)#%d (1) {
205  ["num"]=>
206  string(1) "0"
207}
208object(GMP)#%d (1) {
209  ["num"]=>
210  string(2) "59"
211}
212object(GMP)#%d (1) {
213  ["num"]=>
214  string(2) "59"
215}
216object(GMP)#%d (1) {
217  ["num"]=>
218  string(2) "59"
219}
220object(GMP)#%d (1) {
221  ["num"]=>
222  string(7) "5505024"
223}
224object(GMP)#%d (1) {
225  ["num"]=>
226  string(7) "5505024"
227}
228object(GMP)#%d (1) {
229  ["num"]=>
230  string(7) "5505024"
231}
232object(GMP)#%d (1) {
233  ["num"]=>
234  string(2) "10"
235}
236object(GMP)#%d (1) {
237  ["num"]=>
238  string(3) "-11"
239}
240
241Warning: main(): Shift cannot be negative in %s on line %d
242bool(false)
243
244Warning: main(): Shift cannot be negative in %s on line %d
245bool(false)
246object(GMP)#%d (1) {
247  ["num"]=>
248  string(3) "-43"
249}
250object(GMP)#%d (1) {
251  ["num"]=>
252  string(3) "-42"
253}
254object(GMP)#%d (1) {
255  ["num"]=>
256  string(2) "42"
257}
258bool(false)
259bool(true)
260bool(false)
261bool(false)
262bool(true)
263bool(true)
264bool(true)
265bool(false)
266bool(true)
267bool(false)
268bool(false)
269bool(true)
270bool(false)
271bool(true)
272
273Warning: main(): Unable to convert variable to GMP - wrong type in %s on line %d
274bool(false)
275object(GMP)#%d (1) {
276  ["num"]=>
277  string(2) "43"
278}
279object(GMP)#%d (1) {
280  ["num"]=>
281  string(2) "42"
282}
283object(GMP)#%d (1) {
284  ["num"]=>
285  string(2) "43"
286}
287object(GMP)#%d (1) {
288  ["num"]=>
289  string(2) "43"
290}
291object(GMP)#%d (1) {
292  ["num"]=>
293  string(2) "44"
294}
295object(GMP)#%d (1) {
296  ["num"]=>
297  string(2) "43"
298}
299object(GMP)#%d (1) {
300  ["num"]=>
301  string(2) "43"
302}
303object(GMP)#%d (1) {
304  ["num"]=>
305  string(2) "42"
306}
307string(4) "4217"
308string(4) "4217"
309string(4) "4217"
310string(4) "4217"
311