1--TEST--
2Test str_pad() function : usage variations - unexpected inputs for '$input' 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 '$input'
11 *  and expected type for '$pad_length'
12*/
13
14echo "*** Testing str_pad() function: with unexpected inputs for 'input' 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//getting the resource
28$file_handle = fopen(__FILE__, "r");
29
30// array with different values for $input
31$inputs =  array (
32
33		  // integer values
34/*1*/	  0,
35		  1,
36		  -2,
37		  2147483647,
38		  -2147483648,
39
40		  // float values
41/*6*/	  10.5,
42		  -20.5,
43		  10.1234567e10,
44
45		  // array values
46/*9*/	  array(),
47		  array(0),
48		  array(1, 2),
49
50		  // boolean values
51/*12*/	  true,
52		  false,
53		  TRUE,
54		  FALSE,
55
56		  // null vlaues
57/*16*/	  NULL,
58		  null,
59
60		  // objects
61/*18*/	  new sample(),
62
63		  // resource
64/*19*/	  $file_handle,
65
66		  // undefined variable
67/*20*/	  @$undefined_var,
68
69		  // unset variable
70/*21*/	  @$unset_var
71);
72
73//defining '$pad_length' argument
74$pad_length = "20";
75
76// loop through with each element of the $inputs array to test str_pad() function
77$count = 1;
78foreach($inputs as $input) {
79  echo "-- Iteration $count --\n";
80  var_dump( str_pad($input, $pad_length) );
81  $count ++;
82}
83
84fclose($file_handle);  //closing the file handle
85
86?>
87===DONE===
88--EXPECTF--
89*** Testing str_pad() function: with unexpected inputs for 'input' argument ***
90-- Iteration 1 --
91string(20) "0                   "
92-- Iteration 2 --
93string(20) "1                   "
94-- Iteration 3 --
95string(20) "-2                  "
96-- Iteration 4 --
97string(20) "2147483647          "
98-- Iteration 5 --
99string(20) "-2147483648         "
100-- Iteration 6 --
101string(20) "10.5                "
102-- Iteration 7 --
103string(20) "-20.5               "
104-- Iteration 8 --
105string(20) "101234567000        "
106-- Iteration 9 --
107
108Warning: str_pad() expects parameter 1 to be string, array given in %s on line %d
109NULL
110-- Iteration 10 --
111
112Warning: str_pad() expects parameter 1 to be string, array given in %s on line %d
113NULL
114-- Iteration 11 --
115
116Warning: str_pad() expects parameter 1 to be string, array given in %s on line %d
117NULL
118-- Iteration 12 --
119string(20) "1                   "
120-- Iteration 13 --
121string(20) "                    "
122-- Iteration 14 --
123string(20) "1                   "
124-- Iteration 15 --
125string(20) "                    "
126-- Iteration 16 --
127string(20) "                    "
128-- Iteration 17 --
129string(20) "                    "
130-- Iteration 18 --
131string(20) "sample object       "
132-- Iteration 19 --
133
134Warning: str_pad() expects parameter 1 to be string, resource given in %s on line %d
135NULL
136-- Iteration 20 --
137string(20) "                    "
138-- Iteration 21 --
139string(20) "                    "
140===DONE===
141