xref: /PHP-8.1/ext/gmp/tests/gmp_sub.phpt (revision e9f783fc)
1--TEST--
2gmp_sub() tests
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8try {
9    var_dump(gmp_sub("", ""));
10} catch (\ValueError $e) {
11    echo $e->getMessage() . \PHP_EOL;
12}
13try {
14    var_dump(gmp_sub(array(), array()));
15} catch (\TypeError $e) {
16    echo $e->getMessage() . \PHP_EOL;
17}
18
19var_dump($g = gmp_sub(10000, 10001));
20var_dump(gmp_strval($g));
21var_dump($g = gmp_sub(10000, -1));
22var_dump(gmp_strval($g));
23
24try {
25    var_dump($g = gmp_sub(10000, new stdclass));
26    var_dump(gmp_strval($g));
27} catch (\TypeError $e) {
28    echo $e->getMessage() . \PHP_EOL;
29}
30try {
31    var_dump($g = gmp_sub(new stdclass, 100));
32    var_dump(gmp_strval($g));
33} catch (\TypeError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37echo "Done\n";
38?>
39--EXPECT--
40gmp_sub(): Argument #1 ($num1) is not an integer string
41gmp_sub(): Argument #1 ($num1) must be of type GMP|string|int, array given
42object(GMP)#1 (1) {
43  ["num"]=>
44  string(2) "-1"
45}
46string(2) "-1"
47object(GMP)#3 (1) {
48  ["num"]=>
49  string(5) "10001"
50}
51string(5) "10001"
52gmp_sub(): Argument #2 ($num2) must be of type GMP|string|int, stdClass given
53gmp_sub(): Argument #1 ($num1) must be of type GMP|string|int, stdClass given
54Done
55