1--TEST--
2str_pad() function: usage variations - Non printable chars
3--INI--
4precision=14
5--FILE--
6<?php
7// Split from str_pad for NUL Bytes
8// 7-bit ASCII
9$string = chr(0).chr(255).chr(128).chr(234).chr(143);
10
11/* different pad_lengths */
12$pad_lengths = [
13    -PHP_INT_MAX,  // huge negative value
14    -1,  // negative value
15    0,  // pad_length < sizeof(input_string)
16    9,  // pad_length <= sizeof(input_string)
17    10,  // pad_length > sizeof(input_string)
18    16,  // pad_length > sizeof(input_string)
19];
20
21$pad_string = "=";
22
23/*loop through to use each variant of $pad_length on
24  each element of $input_strings array */
25foreach ($pad_lengths as $pad_length ) {
26    // default pad_string & pad_type
27    var_dump( bin2hex( str_pad($string, $pad_length) ) );
28    // default pad_type
29    var_dump( bin2hex( str_pad($string, $pad_length, $pad_string) ) );
30    var_dump( bin2hex( str_pad($string, $pad_length, $pad_string, STR_PAD_LEFT) ) );
31    var_dump( bin2hex( str_pad($string, $pad_length, $pad_string, STR_PAD_RIGHT) ) );
32    var_dump( bin2hex( str_pad($string, $pad_length, $pad_string, STR_PAD_BOTH) ) );
33}
34
35?>
36
37DONE
38--EXPECT--
39string(10) "00ff80ea8f"
40string(10) "00ff80ea8f"
41string(10) "00ff80ea8f"
42string(10) "00ff80ea8f"
43string(10) "00ff80ea8f"
44string(10) "00ff80ea8f"
45string(10) "00ff80ea8f"
46string(10) "00ff80ea8f"
47string(10) "00ff80ea8f"
48string(10) "00ff80ea8f"
49string(10) "00ff80ea8f"
50string(10) "00ff80ea8f"
51string(10) "00ff80ea8f"
52string(10) "00ff80ea8f"
53string(10) "00ff80ea8f"
54string(18) "00ff80ea8f20202020"
55string(18) "00ff80ea8f3d3d3d3d"
56string(18) "3d3d3d3d00ff80ea8f"
57string(18) "00ff80ea8f3d3d3d3d"
58string(18) "3d3d00ff80ea8f3d3d"
59string(20) "00ff80ea8f2020202020"
60string(20) "00ff80ea8f3d3d3d3d3d"
61string(20) "3d3d3d3d3d00ff80ea8f"
62string(20) "00ff80ea8f3d3d3d3d3d"
63string(20) "3d3d00ff80ea8f3d3d3d"
64string(32) "00ff80ea8f2020202020202020202020"
65string(32) "00ff80ea8f3d3d3d3d3d3d3d3d3d3d3d"
66string(32) "3d3d3d3d3d3d3d3d3d3d3d00ff80ea8f"
67string(32) "00ff80ea8f3d3d3d3d3d3d3d3d3d3d3d"
68string(32) "3d3d3d3d3d00ff80ea8f3d3d3d3d3d3d"
69
70DONE
71