summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/strval.phpt
blob: b2c5cd8b76573a4ef8d0c13a61b8ae09cc9a5927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
--TEST--
Test strval() function
--INI--
precision=14
--FILE--
<?php
/* Prototype: string strval ( mixed $var );
 * Description: Returns the string value of var
 */

echo "*** Testing str_val() with scalar values***\n";
$heredoc_string = <<<EOD
This is a multiline heredoc
string. Numeric = 1232455.
EOD;
/* heredoc string with only numeric values */
$heredoc_numeric_string = <<<EOD
12345
2345
EOD;
/* null heredoc string */
$heredoc_empty_string = <<<EOD
EOD;
/* heredoc string with NULL */
$heredoc_NULL_string = <<<EOD
NULL
EOD;

// different valid  scalar vlaues
$scalars = array(
  /* integers */
  0,
  1,
  -1,
  -2147483648, // max negative integer value
  -2147483647,
  2147483647,  // max positive integer value
  2147483640,
  0x123B,      // integer as hexadecimal
  0x12ab,
  0Xfff,
  0XFA,

  /* floats */
  -0x80000000, // max negative integer as hexadecimal
  0x7fffffff,  // max positive integer as hexadecimal
  0x7FFFFFFF,  // max positive integer as hexadecimal
  0123,        // integer as octal
  01,       // should be quivalent to octal 1
  -020000000000, // max negative integer as octal
  017777777777,  // max positive integer as octal
  -2147483649, // float value
  2147483648,  // float value
  -0x80000001, // float value, beyond max negative int
  0x800000001, // float value, beyond max positive int
  020000000001, // float value, beyond max positive int
  -020000000001, // float value, beyond max negative int
  0.0,
  -0.1,
  10.0000000000000000005,
  10.5e+5,
  1e-5,
  .5e+7,
  .6e-19,
  .05E+44,
  .0034E-30,

  /* booleans */
  true,
  TRUE,
  FALSE,
  false,

  /* strings */
  "",
  '',
  " ",
  ' ',
  '0',
  "0",
  "testing",
  "0x564",
  "0123",
  "new\n",
  'new\n',
  "@#$$%^&&*()",
  "        ",
  "null",
  'null',
  'true',
  "true",
  /*"\0123",
  "\0x12FF",*/
  $heredoc_string,
  $heredoc_numeric_string,
  $heredoc_empty_string
);
/* loop to check that strval() recognizes different
   scalar values and retuns the string conversion of same */
$loop_counter = 1;
foreach ($scalars as $scalar ) {
   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
   var_dump( strval($scalar) );
}

echo "\n*** Testing strval() with non_scalar values ***\n";
// get a resource type variable
$fp = fopen(__FILE__, "r");
$dfp = opendir( dirname(__FILE__) );

// unset variable
$unset_var = 10;
unset ($unset_var);

// non_scalar values, objects, arrays, resources and boolean
class foo
{
  function __toString() {
    return "Object";
  }
}

$not_scalars = array (
  new foo, //object
  $fp,  // resource
  $dfp,
  array(),  // arrays
  array(NULL),
  array(1,2,3,4),
  array("string"),
  NULL,  // nulls
  null,
  @$unset_var,  // unset variable
  @$undefined_var
);
/* loop through the $not_scalars to see working of
   strval() on objects, arrays, boolean and others */
$loop_counter = 1;
foreach ($not_scalars as $value ) {
   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
   var_dump( strval($value) );
}

echo "\n*** Testing error conditions ***\n";
//Zero argument
var_dump( strval() );

//arguments more than expected
var_dump( strval( $scalars[0], $scalars[1]) );

echo "Done\n";

// close the resources used
fclose($fp);
closedir($dfp);

?>
--EXPECTF--
*** Testing str_val() with scalar values***
-- Iteration 1 --
string(1) "0"
-- Iteration 2 --
string(1) "1"
-- Iteration 3 --
string(2) "-1"
-- Iteration 4 --
string(11) "-2147483648"
-- Iteration 5 --
string(11) "-2147483647"
-- Iteration 6 --
string(10) "2147483647"
-- Iteration 7 --
string(10) "2147483640"
-- Iteration 8 --
string(4) "4667"
-- Iteration 9 --
string(4) "4779"
-- Iteration 10 --
string(4) "4095"
-- Iteration 11 --
string(3) "250"
-- Iteration 12 --
string(11) "-2147483648"
-- Iteration 13 --
string(10) "2147483647"
-- Iteration 14 --
string(10) "2147483647"
-- Iteration 15 --
string(2) "83"
-- Iteration 16 --
string(1) "1"
-- Iteration 17 --
string(11) "-2147483648"
-- Iteration 18 --
string(10) "2147483647"
-- Iteration 19 --
string(11) "-2147483649"
-- Iteration 20 --
string(10) "2147483648"
-- Iteration 21 --
string(11) "-2147483649"
-- Iteration 22 --
string(11) "34359738369"
-- Iteration 23 --
string(10) "2147483649"
-- Iteration 24 --
string(11) "-2147483649"
-- Iteration 25 --
string(1) "0"
-- Iteration 26 --
string(4) "-0.1"
-- Iteration 27 --
string(2) "10"
-- Iteration 28 --
string(7) "1050000"
-- Iteration 29 --
string(6) "1.0E-5"
-- Iteration 30 --
string(7) "5000000"
-- Iteration 31 --
string(7) "6.0E-20"
-- Iteration 32 --
string(7) "5.0E+42"
-- Iteration 33 --
string(7) "3.4E-33"
-- Iteration 34 --
string(1) "1"
-- Iteration 35 --
string(1) "1"
-- Iteration 36 --
string(0) ""
-- Iteration 37 --
string(0) ""
-- Iteration 38 --
string(0) ""
-- Iteration 39 --
string(0) ""
-- Iteration 40 --
string(1) " "
-- Iteration 41 --
string(1) " "
-- Iteration 42 --
string(1) "0"
-- Iteration 43 --
string(1) "0"
-- Iteration 44 --
string(7) "testing"
-- Iteration 45 --
string(5) "0x564"
-- Iteration 46 --
string(4) "0123"
-- Iteration 47 --
string(4) "new
"
-- Iteration 48 --
string(5) "new\n"
-- Iteration 49 --
string(11) "@#$$%^&&*()"
-- Iteration 50 --
string(8) "        "
-- Iteration 51 --
string(4) "null"
-- Iteration 52 --
string(4) "null"
-- Iteration 53 --
string(4) "true"
-- Iteration 54 --
string(4) "true"
-- Iteration 55 --
string(5%d) "This is a multiline heredoc
string. Numeric = 1232455."
-- Iteration 56 --
string(1%d) "12345
2345"
-- Iteration 57 --
string(0) ""

*** Testing strval() with non_scalar values ***
-- Iteration 1 --
string(6) "Object"
-- Iteration 2 --
string(14) "Resource id #%d"
-- Iteration 3 --
string(14) "Resource id #%d"
-- Iteration 4 --

Notice: Array to string conversion in %sstrval.php on line %d
string(5) "Array"
-- Iteration 5 --

Notice: Array to string conversion in %sstrval.php on line %d
string(5) "Array"
-- Iteration 6 --

Notice: Array to string conversion in %sstrval.php on line %d
string(5) "Array"
-- Iteration 7 --

Notice: Array to string conversion in %sstrval.php on line %d
string(5) "Array"
-- Iteration 8 --
string(0) ""
-- Iteration 9 --
string(0) ""
-- Iteration 10 --
string(0) ""
-- Iteration 11 --
string(0) ""

*** Testing error conditions ***

Warning: strval() expects exactly 1 parameter, 0 given in %s on line %d
NULL

Warning: strval() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Done