xref: /PHP-8.1/ext/standard/tests/math/bug30695.phpt (revision b8e380ab)
1--TEST--
2Bug #30695 (32 bit issues)
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
6?>
7--FILE--
8<?php
9    function toUTF8( $char_code )
10    {
11        switch ( $char_code )
12        {
13            case 0:
14                $char = chr( 0 );
15                break;
16            case !($char_code & 0xffffff80): // 7 bit
17                $char = chr( $char_code );
18                break;
19            case !($char_code & 0xfffff800): // 11 bit
20                $char = ( chr(0xc0 | (($char_code >> 6) & 0x1f)) .
21                          chr(0x80 | ($char_code & 0x3f)) );
22                break;
23            case !($char_code & 0xffff0000): // 16 bit
24                $char = ( chr(0xe0 | (($char_code >> 12) & 0x0f)) .
25                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
26                          chr(0x80 | ($char_code & 0x3f)) );
27                break;
28            case !($char_code & 0xffe00000): // 21 bit
29                $char = ( chr(0xf0 | (($char_code >> 18) & 0x07)) .
30                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
31                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
32                          chr(0x80 | ($char_code & 0x3f)) );
33                break;
34            case !($char_code & 0xfc000000): // 26 bit
35                $char = ( chr(0xf8 | (($char_code >> 24) & 0x03)) .
36                          chr(0x80 | (($char_code >> 18) & 0x3f)) .
37                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
38                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
39                          chr(0x80 | ($char_code & 0x3f)) );
40                break;
41            default: // 31 bit
42                $char = ( chr(0xfc | (($char_code >> 30) & 0x01)) .
43                          chr(0x80 | (($char_code >> 24) & 0x3f)) .
44                          chr(0x80 | (($char_code >> 18) & 0x3f)) .
45                          chr(0x80 | (($char_code >> 12) & 0x3f)) .
46                          chr(0x80 | (($char_code >> 6) & 0x3f)) .
47                          chr(0x80 | ($char_code & 0x3f)) );
48        }
49        return $char;
50    }
51
52
53    echo "\n", toUTF8(65), "\n", toUTF8(233), "\n", toUTF8(1252), "\n", toUTF8(20095), "\n";
54?>
55--EXPECTF--
56Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
57A
58
59Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
60
61Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
62é
63
64Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
65
66Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
67Ӥ
68
69Deprecated: Implicit conversion from float 4294967168 to int loses precision in %s on line %d
70
71Deprecated: Implicit conversion from float 4294965248 to int loses precision in %s on line %d
72
73Deprecated: Implicit conversion from float 4294901760 to int loses precision in %s on line %d
74乿
75