xref: /PHP-7.4/ext/json/tests/inf_nan_error.phpt (revision ded3d984)
1--TEST--
2An error is thrown when INF or NaN are encoded
3--SKIPIF--
4<?php if (!extension_loaded("json")) print "skip"; ?>
5--FILE--
6<?php
7
8$inf = INF;
9
10var_dump($inf);
11
12var_dump(json_encode($inf));
13var_dump(json_last_error(), json_last_error_msg());
14
15var_dump(json_encode($inf, JSON_PARTIAL_OUTPUT_ON_ERROR));
16var_dump(json_last_error(), json_last_error_msg());
17
18echo "\n";
19
20$nan = NAN;
21
22var_dump($nan);
23
24var_dump(json_encode($nan));
25var_dump(json_last_error(), json_last_error_msg());
26
27var_dump(json_encode($nan, JSON_PARTIAL_OUTPUT_ON_ERROR));
28var_dump(json_last_error(), json_last_error_msg());
29?>
30--EXPECT--
31float(INF)
32bool(false)
33int(7)
34string(34) "Inf and NaN cannot be JSON encoded"
35string(1) "0"
36int(7)
37string(34) "Inf and NaN cannot be JSON encoded"
38
39float(NAN)
40bool(false)
41int(7)
42string(34) "Inf and NaN cannot be JSON encoded"
43string(1) "0"
44int(7)
45string(34) "Inf and NaN cannot be JSON encoded"
46