summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/intval_binary_prefix.phpt
blob: 47b8d05386d5fd6a30dc38904adab35a6caa8820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
--TEST--
Test intval() function with "0b" string prefix
--FILE--
<?php

$isspaceChars = " \t\n\r\f\v";

$goodInputs = [
    '0b1111111111111111111111111111111',
    '+0b1111111111111111111111111111111',
    '-0b1111111111111111111111111111111',
    $isspaceChars . '0b1111111111111111111111111111111',
    $isspaceChars . '+0b1111111111111111111111111111111',
    $isspaceChars . '-0b1111111111111111111111111111111',
    '0b',
    '0B',
    '0B1',
    '0b000',
    '0b001',
    '0b00100',
    '0b1 1'
];

$badInputs = [
    'b101',
    '0b00200',
    '--0b123',
    '++0b123',
    '0bb123',
    '0 b123',
];

print "--- Good Inputs - Base = 0 ---\n";

foreach ($goodInputs as $input) {
    var_dump(
        intval($input, 0)
    );
}

print "--- Good Inputs - Base = 2 ---\n";

foreach ($goodInputs as $input) {
    var_dump(
        intval($input, 2)
    );
}

print "--- Good Inputs - Base = default ---\n";

foreach ($goodInputs as $input) {
    var_dump(
        intval($input)
    );
}

print "--- Bad Inputs - Base = 0 ---\n";

foreach ($badInputs as $input) {
    var_dump(
        intval($input, 0)
    );
}

print '--- Done ---';

?>
--EXPECT--
--- Good Inputs - Base = 0 ---
int(2147483647)
int(2147483647)
int(-2147483647)
int(2147483647)
int(2147483647)
int(-2147483647)
int(0)
int(0)
int(1)
int(0)
int(1)
int(4)
int(1)
--- Good Inputs - Base = 2 ---
int(2147483647)
int(2147483647)
int(-2147483647)
int(2147483647)
int(2147483647)
int(-2147483647)
int(0)
int(0)
int(1)
int(0)
int(1)
int(4)
int(1)
--- Good Inputs - Base = default ---
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
--- Bad Inputs - Base = 0 ---
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
--- Done ---