1--TEST--
2Test strrev() function : usage variations - unexpected inputs
3--FILE--
4<?php
5/* Prototype  : string strrev(string $str);
6 * Description: Reverse a string
7 * Source code: ext/standard/string.c
8*/
9
10/* Testing strrev() function with unexpected inputs for 'str' */
11
12echo "*** Testing strrev() : unexpected inputs for 'str' ***\n";
13//class declaration
14class sample {
15  public function __toString(){
16    return "object";
17  }
18}
19
20//get the resource
21$resource = fopen(__FILE__, "r");
22
23//get an unset variable
24$unset_var = 10;
25unset ($unset_var);
26
27//array of values to iterate over
28$values = array(
29
30  // int data
31  0,
32  1,
33  12345,
34  -2345,
35
36  // float data
37  10.5,
38   -10.5,
39  10.5e10,
40  10.6E-10,
41  .5,
42
43  // array data
44  array(),
45  array(0),
46  array(1),
47  array(1, 2),
48  array('color' => 'red', 'item' => 'pen'),
49
50  // null data
51  NULL,
52  null,
53
54  // boolean data
55  true,
56  false,
57  TRUE,
58  FALSE,
59
60  // empty data
61  "",
62  '',
63
64  // object data
65  new sample(),
66
67  // resource
68  $resource,
69
70  // undefined data
71  @$undefined_var,
72
73  // unset data
74  @$unset_var
75);
76
77// loop through each element of the array for str
78
79$count = 1;
80foreach($values as $value) {
81  echo "\n-- Iterator $count --\n";
82  var_dump( strrev($value) );
83  $count++;
84};
85
86fclose($resource);  //closing the file handle
87
88echo "*** Done ***";
89?>
90--EXPECTF--
91*** Testing strrev() : unexpected inputs for 'str' ***
92
93-- Iterator 1 --
94string(1) "0"
95
96-- Iterator 2 --
97string(1) "1"
98
99-- Iterator 3 --
100string(5) "54321"
101
102-- Iterator 4 --
103string(5) "5432-"
104
105-- Iterator 5 --
106string(4) "5.01"
107
108-- Iterator 6 --
109string(5) "5.01-"
110
111-- Iterator 7 --
112string(12) "000000000501"
113
114-- Iterator 8 --
115string(7) "9-E60.1"
116
117-- Iterator 9 --
118string(3) "5.0"
119
120-- Iterator 10 --
121
122Warning: strrev() expects parameter 1 to be string, array given in %s on line %d
123NULL
124
125-- Iterator 11 --
126
127Warning: strrev() expects parameter 1 to be string, array given in %s on line %d
128NULL
129
130-- Iterator 12 --
131
132Warning: strrev() expects parameter 1 to be string, array given in %s on line %d
133NULL
134
135-- Iterator 13 --
136
137Warning: strrev() expects parameter 1 to be string, array given in %s on line %d
138NULL
139
140-- Iterator 14 --
141
142Warning: strrev() expects parameter 1 to be string, array given in %s on line %d
143NULL
144
145-- Iterator 15 --
146string(0) ""
147
148-- Iterator 16 --
149string(0) ""
150
151-- Iterator 17 --
152string(1) "1"
153
154-- Iterator 18 --
155string(0) ""
156
157-- Iterator 19 --
158string(1) "1"
159
160-- Iterator 20 --
161string(0) ""
162
163-- Iterator 21 --
164string(0) ""
165
166-- Iterator 22 --
167string(0) ""
168
169-- Iterator 23 --
170string(6) "tcejbo"
171
172-- Iterator 24 --
173
174Warning: strrev() expects parameter 1 to be string, resource given in %s on line %d
175NULL
176
177-- Iterator 25 --
178string(0) ""
179
180-- Iterator 26 --
181string(0) ""
182*** Done ***
183