1--TEST--
2Test intval() function with "0b" string prefix
3--FILE--
4<?php
5
6$isspaceChars = " \t\n\r\f\v";
7
8$goodInputs = [
9    '0b1111111111111111111111111111111',
10    '+0b1111111111111111111111111111111',
11    '-0b1111111111111111111111111111111',
12    $isspaceChars . '0b1111111111111111111111111111111',
13    $isspaceChars . '+0b1111111111111111111111111111111',
14    $isspaceChars . '-0b1111111111111111111111111111111',
15    '0b',
16    '0B',
17    '0B1',
18    '0b000',
19    '0b001',
20    '0b00100',
21    '0b1 1'
22];
23
24$badInputs = [
25    'b101',
26    '0b00200',
27    '--0b123',
28    '++0b123',
29    '0bb123',
30    '0 b123',
31];
32
33print "--- Good Inputs - Base = 0 ---\n";
34
35foreach ($goodInputs as $input) {
36    var_dump(
37        intval($input, 0)
38    );
39}
40
41print "--- Good Inputs - Base = 2 ---\n";
42
43foreach ($goodInputs as $input) {
44    var_dump(
45        intval($input, 2)
46    );
47}
48
49print "--- Good Inputs - Base = default ---\n";
50
51foreach ($goodInputs as $input) {
52    var_dump(
53        intval($input)
54    );
55}
56
57print "--- Bad Inputs - Base = 0 ---\n";
58
59foreach ($badInputs as $input) {
60    var_dump(
61        intval($input, 0)
62    );
63}
64
65print '--- Done ---';
66
67?>
68--EXPECT--
69--- Good Inputs - Base = 0 ---
70int(2147483647)
71int(2147483647)
72int(-2147483647)
73int(2147483647)
74int(2147483647)
75int(-2147483647)
76int(0)
77int(0)
78int(1)
79int(0)
80int(1)
81int(4)
82int(1)
83--- Good Inputs - Base = 2 ---
84int(2147483647)
85int(2147483647)
86int(-2147483647)
87int(2147483647)
88int(2147483647)
89int(-2147483647)
90int(0)
91int(0)
92int(1)
93int(0)
94int(1)
95int(4)
96int(1)
97--- Good Inputs - Base = default ---
98int(0)
99int(0)
100int(0)
101int(0)
102int(0)
103int(0)
104int(0)
105int(0)
106int(0)
107int(0)
108int(0)
109int(0)
110int(0)
111--- Bad Inputs - Base = 0 ---
112int(0)
113int(0)
114int(0)
115int(0)
116int(0)
117int(0)
118--- Done ---
119