xref: /PHP-8.0/ext/mbstring/tests/mb_chr.phpt (revision 226d9dd3)
1--TEST--
2mb_chr()
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--FILE--
6<?php
7var_dump(
8    "\u{20bb7}" === mb_chr(0x20bb7),
9    "\x8f\xa1\xef" === mb_chr(0x50aa, "EUC-JP-2004"),
10    false === mb_chr(0xd800),
11    false === mb_chr(0x1f600, "EUC-JP-2004")
12);
13
14// Invalid
15try {
16    var_dump( mb_chr(0xd800, "typo") );
17} catch (\ValueError $e) {
18    echo $e->getMessage() . \PHP_EOL;
19}
20try {
21    var_dump( mb_chr(0xd800, "pass") );
22} catch (\ValueError $e) {
23    echo $e->getMessage() . \PHP_EOL;
24}
25try {
26    var_dump( mb_chr(0xd800, "jis") );
27} catch (\ValueError $e) {
28    echo $e->getMessage() . \PHP_EOL;
29}
30try {
31    var_dump( mb_chr(0xd800, "cp50222") );
32} catch (\ValueError $e) {
33    echo $e->getMessage() . \PHP_EOL;
34}
35try {
36    var_dump( mb_chr(0xd800, "utf-7") );
37} catch (\ValueError $e) {
38    echo $e->getMessage() . \PHP_EOL;
39}
40
41mb_internal_encoding("utf-7");
42try {
43    var_dump( mb_chr(0xd800) );
44} catch (\ValueError $e) {
45    echo $e->getMessage() . \PHP_EOL;
46}
47
48?>
49--EXPECT--
50bool(true)
51bool(true)
52bool(true)
53bool(true)
54mb_chr(): Argument #2 ($encoding) must be a valid encoding, "typo" given
55mb_chr(): Argument #2 ($encoding) must be a valid encoding, "pass" given
56mb_chr() does not support the "JIS" encoding
57mb_chr() does not support the "CP50222" encoding
58mb_chr() does not support the "UTF-7" encoding
59mb_chr() does not support the "UTF-7" encoding
60