1--TEST--
2Test ucwords() function : usage variations - unexpected input values
3--FILE--
4<?php
5/* Prototype  : string ucwords ( string $str )
6 * Description: Uppercase the first character of each word in a string
7 * Source code: ext/standard/string.c
8*/
9
10/*
11 * Test ucwords() by passing different values including scalar and non scalar values
12*/
13
14echo "*** Testing ucwords() : usage variations ***\n";
15// initialize all required variables
16
17// get an unset variable
18$unset_var = 'string_val';
19unset($unset_var);
20
21$fp = fopen(__FILE__, "r");
22
23class my
24{
25  function __toString() {
26    return "myString";
27  }
28}
29
30// array with different values
31$values =  array (
32
33  // integer values
34  0,
35  1,
36  12345,
37  -2345,
38
39  // hex values
40  0x10,
41  0X20,
42  0xAA,
43  -0XF5,
44
45  // octal values
46  0123,
47  -0342,
48
49  // float values
50  10.5,
51  -10.5,
52  10.1234567e10,
53  10.7654321E-10,
54  .5,
55
56  // array values
57  array(),
58  array(0),
59  array(1),
60  array(1, 2),
61  array('color' => 'red', 'item' => 'pen'),
62
63  // boolean values
64  true,
65  false,
66  TRUE,
67  FALSE,
68
69  // objects
70  new my(),
71
72  // empty string
73  "",
74  '',
75
76  //NULL
77  NULL,
78  null,
79
80  // hex in string
81  "0x123",
82  '0x123',
83  "0xFF12",
84  "-0xFF12",
85
86  // undefined variable
87  @$undefined_var,
88
89  // unset variable
90  @$unset_var,
91
92  // resource variable
93  $fp
94);
95
96// loop through each element of the array and check the working of ucwords()
97// when $str argument is supplied with different values
98echo "\n--- Testing ucwords() by supplying different values for 'str' argument ---\n";
99$counter = 1;
100for($index = 0; $index < count($values); $index ++) {
101  echo "-- Iteration $counter --\n";
102  $str = $values [$index];
103
104  var_dump( ucwords($str) );
105
106  $counter ++;
107}
108
109// close the file handle
110fclose($fp);
111echo "Done\n";
112?>
113--EXPECTF--
114*** Testing ucwords() : usage variations ***
115
116--- Testing ucwords() by supplying different values for 'str' argument ---
117-- Iteration 1 --
118string(1) "0"
119-- Iteration 2 --
120string(1) "1"
121-- Iteration 3 --
122string(5) "12345"
123-- Iteration 4 --
124string(5) "-2345"
125-- Iteration 5 --
126string(2) "16"
127-- Iteration 6 --
128string(2) "32"
129-- Iteration 7 --
130string(3) "170"
131-- Iteration 8 --
132string(4) "-245"
133-- Iteration 9 --
134string(2) "83"
135-- Iteration 10 --
136string(4) "-226"
137-- Iteration 11 --
138string(4) "10.5"
139-- Iteration 12 --
140string(5) "-10.5"
141-- Iteration 13 --
142string(12) "101234567000"
143-- Iteration 14 --
144string(13) "1.07654321E-9"
145-- Iteration 15 --
146string(3) "0.5"
147-- Iteration 16 --
148
149Warning: ucwords() expects parameter 1 to be string, array given in %s on line %d
150NULL
151-- Iteration 17 --
152
153Warning: ucwords() expects parameter 1 to be string, array given in %s on line %d
154NULL
155-- Iteration 18 --
156
157Warning: ucwords() expects parameter 1 to be string, array given in %s on line %d
158NULL
159-- Iteration 19 --
160
161Warning: ucwords() expects parameter 1 to be string, array given in %s on line %d
162NULL
163-- Iteration 20 --
164
165Warning: ucwords() expects parameter 1 to be string, array given in %s on line %d
166NULL
167-- Iteration 21 --
168string(1) "1"
169-- Iteration 22 --
170string(0) ""
171-- Iteration 23 --
172string(1) "1"
173-- Iteration 24 --
174string(0) ""
175-- Iteration 25 --
176string(8) "MyString"
177-- Iteration 26 --
178string(0) ""
179-- Iteration 27 --
180string(0) ""
181-- Iteration 28 --
182string(0) ""
183-- Iteration 29 --
184string(0) ""
185-- Iteration 30 --
186string(5) "0x123"
187-- Iteration 31 --
188string(5) "0x123"
189-- Iteration 32 --
190string(6) "0xFF12"
191-- Iteration 33 --
192string(7) "-0xFF12"
193-- Iteration 34 --
194string(0) ""
195-- Iteration 35 --
196string(0) ""
197-- Iteration 36 --
198
199Warning: ucwords() expects parameter 1 to be string, resource given in %s on line %d
200NULL
201Done
202