1--TEST--
2Test str_pad() function : usage variations - unexpected inputs for '$pad_type' argument
3--SKIPIF--
4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only");
5--FILE--
6<?php
7/* Prototype  : string str_pad  ( string $input  , int $pad_length  [, string $pad_string  [, int $pad_type  ]] )
8 * Description: Pad a string to a certain length with another string
9 * Source code: ext/standard/string.c
10*/
11
12/* Test str_pad() function: with unexpected inputs for '$pad_type'
13 *  and expected type for '$input', '$pad_length' and '$pad_string'
14*/
15
16echo "*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***\n";
17
18//get an unset variable
19$unset_var = 'string_val';
20unset($unset_var);
21
22//defining a class
23class sample  {
24  public function __toString() {
25    return "sample object";
26  }
27}
28
29// array with different values for $input
30$pad_types =  array (
31
32		  // integer values
33/*1*/	  0, // == STR_PAD_LEFT
34		  1, // == STR_PAD_RIGHT
35		  2, // == STR_PAD_BOTH
36		  -2,
37		  2147483647,
38		  -2147483648,
39
40		  // float values
41/*7*/	  10.5,
42		  -20.5,
43		  10.1234567e10,
44
45		  // string data
46/*10*/	  "abc",
47		  "STR_PAD_LEFT",
48		  "2",
49		  "0x2",
50		  "02",
51
52		  // array values
53/*15*/	  array(),
54		  array(0),
55		  array(1, 2),
56
57		  // boolean values
58/*18*/	  true,
59		  false,
60		  TRUE,
61		  FALSE,
62
63		  // null vlaues
64/*22*/	  NULL,
65		  null,
66
67		  // objects
68/*24*/	  new sample(),
69
70		  // undefined variable
71/*25*/	  @$undefined_var,
72
73		  // unset variable
74/*26*/	  @$unset_var
75);
76
77//defining '$input' argument
78$input = "Test string";
79$pad_length = 20;
80$pad_string = "*";
81
82// loop through with each element of the $pad_types array to test str_pad() function
83$count = 1;
84foreach($pad_types as $pad_type) {
85  echo "-- Iteration $count --\n";
86  var_dump( str_pad($input, $pad_length, $pad_string, $pad_type) );
87  $count ++;
88}
89
90?>
91===DONE===
92--EXPECTF--
93*** Testing str_pad() function: with unexpected inputs for 'pad_type' argument ***
94-- Iteration 1 --
95string(20) "*********Test string"
96-- Iteration 2 --
97string(20) "Test string*********"
98-- Iteration 3 --
99string(20) "****Test string*****"
100-- Iteration 4 --
101
102Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
103NULL
104-- Iteration 5 --
105
106Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
107NULL
108-- Iteration 6 --
109
110Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
111NULL
112-- Iteration 7 --
113
114Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
115NULL
116-- Iteration 8 --
117
118Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
119NULL
120-- Iteration 9 --
121
122Warning: str_pad(): Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s on line %d
123NULL
124-- Iteration 10 --
125
126Warning: str_pad() expects parameter 4 to be integer, string given in %s on line %d
127NULL
128-- Iteration 11 --
129
130Warning: str_pad() expects parameter 4 to be integer, string given in %s on line %d
131NULL
132-- Iteration 12 --
133string(20) "****Test string*****"
134-- Iteration 13 --
135
136Notice: A non well formed numeric value encountered in %s on line %d
137string(20) "*********Test string"
138-- Iteration 14 --
139string(20) "****Test string*****"
140-- Iteration 15 --
141
142Warning: str_pad() expects parameter 4 to be integer, array given in %s on line %d
143NULL
144-- Iteration 16 --
145
146Warning: str_pad() expects parameter 4 to be integer, array given in %s on line %d
147NULL
148-- Iteration 17 --
149
150Warning: str_pad() expects parameter 4 to be integer, array given in %s on line %d
151NULL
152-- Iteration 18 --
153string(20) "Test string*********"
154-- Iteration 19 --
155string(20) "*********Test string"
156-- Iteration 20 --
157string(20) "Test string*********"
158-- Iteration 21 --
159string(20) "*********Test string"
160-- Iteration 22 --
161string(20) "*********Test string"
162-- Iteration 23 --
163string(20) "*********Test string"
164-- Iteration 24 --
165
166Warning: str_pad() expects parameter 4 to be integer, object given in %s on line %d
167NULL
168-- Iteration 25 --
169string(20) "*********Test string"
170-- Iteration 26 --
171string(20) "*********Test string"
172===DONE===
173