xref: /PHP-8.1/ext/gmp/tests/gmp_strict_types.phpt (revision e9f783fc)
1--TEST--
2GMP functions with strict_types=1
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8declare(strict_types=1);
9
10var_dump(gmp_abs(gmp_init(-1)));
11var_dump(gmp_abs(-1));
12var_dump(gmp_abs("-1"));
13try {
14    gmp_abs(1.0);
15} catch (TypeError $e) {
16    echo $e->getMessage(), "\n";
17}
18try {
19    gmp_abs(false);
20} catch (TypeError $e) {
21    echo $e->getMessage(), "\n";
22}
23try {
24    gmp_abs(true);
25} catch (TypeError $e) {
26    echo $e->getMessage(), "\n";
27}
28try {
29    gmp_abs(null);
30} catch (TypeError $e) {
31    echo $e->getMessage(), "\n";
32}
33try {
34    gmp_abs([]);
35} catch (TypeError $e) {
36    echo $e->getMessage(), "\n";
37}
38
39?>
40--EXPECT--
41object(GMP)#2 (1) {
42  ["num"]=>
43  string(1) "1"
44}
45object(GMP)#2 (1) {
46  ["num"]=>
47  string(1) "1"
48}
49object(GMP)#2 (1) {
50  ["num"]=>
51  string(1) "1"
52}
53gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, float given
54gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, bool given
55gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, bool given
56gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, null given
57gmp_abs(): Argument #1 ($num) must be of type GMP|string|int, array given
58