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