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