1--TEST--
2Test strval() function
3--INI--
4precision=14
5--FILE--
6<?php
7echo "*** Testing str_val() with scalar values***\n";
8$heredoc_string = <<<EOD
9This is a multiline heredoc
10string. Numeric = 1232455.
11EOD;
12/* heredoc string with only numeric values */
13$heredoc_numeric_string = <<<EOD
1412345
152345
16EOD;
17/* null heredoc string */
18$heredoc_empty_string = <<<EOD
19EOD;
20/* heredoc string with NULL */
21$heredoc_NULL_string = <<<EOD
22NULL
23EOD;
24
25// different valid  scalar values
26$scalars = array(
27  /* integers */
28  0,
29  1,
30  -1,
31  -2147483648, // max negative integer value
32  -2147483647,
33  2147483647,  // max positive integer value
34  2147483640,
35  0x123B,      // integer as hexadecimal
36  0x12ab,
37  0Xfff,
38  0XFA,
39
40  /* floats */
41  -0x80000000, // max negative integer as hexadecimal
42  0x7fffffff,  // max positive integer as hexadecimal
43  0x7FFFFFFF,  // max positive integer as hexadecimal
44  0123,        // integer as octal
45  01,       // should be quivalent to octal 1
46  -020000000000, // max negative integer as octal
47  017777777777,  // max positive integer as octal
48  -2147483649, // float value
49  2147483648,  // float value
50  -0x80000001, // float value, beyond max negative int
51  0x800000001, // float value, beyond max positive int
52  020000000001, // float value, beyond max positive int
53  -020000000001, // float value, beyond max negative int
54  0.0,
55  -0.1,
56  10.0000000000000000005,
57  10.5e+5,
58  1e-5,
59  .5e+7,
60  .6e-19,
61  .05E+44,
62  .0034E-30,
63
64  /* booleans */
65  true,
66  TRUE,
67  FALSE,
68  false,
69
70  /* strings */
71  "",
72  '',
73  " ",
74  ' ',
75  '0',
76  "0",
77  "testing",
78  "0x564",
79  "0123",
80  "new\n",
81  'new\n',
82  "@#$$%^&&*()",
83  "        ",
84  "null",
85  'null',
86  'true',
87  "true",
88  /*"\0123",
89  "\0x12FF",*/
90  $heredoc_string,
91  $heredoc_numeric_string,
92  $heredoc_empty_string
93);
94/* loop to check that strval() recognizes different
95   scalar values and returns the string conversion of same */
96$loop_counter = 1;
97foreach ($scalars as $scalar ) {
98   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
99   var_dump( strval($scalar) );
100}
101
102echo "\n*** Testing strval() with non_scalar values ***\n";
103// get a resource type variable
104$fp = fopen(__FILE__, "r");
105$dfp = opendir( __DIR__ );
106
107// unset variable
108$unset_var = 10;
109unset ($unset_var);
110
111// non_scalar values, objects, arrays, resources and boolean
112class foo
113{
114  function __toString() {
115    return "Object";
116  }
117}
118
119$not_scalars = array (
120  new foo, //object
121  $fp,  // resource
122  $dfp,
123  array(),  // arrays
124  array(NULL),
125  array(1,2,3,4),
126  array("string"),
127  NULL,  // nulls
128  null,
129  @$unset_var,  // unset variable
130  @$undefined_var
131);
132/* loop through the $not_scalars to see working of
133   strval() on objects, arrays, boolean and others */
134$loop_counter = 1;
135foreach ($not_scalars as $value ) {
136   echo "-- Iteration $loop_counter --\n"; $loop_counter++;
137   var_dump( strval($value) );
138}
139
140echo "Done\n";
141
142// close the resources used
143fclose($fp);
144closedir($dfp);
145
146?>
147--EXPECTF--
148*** Testing str_val() with scalar values***
149-- Iteration 1 --
150string(1) "0"
151-- Iteration 2 --
152string(1) "1"
153-- Iteration 3 --
154string(2) "-1"
155-- Iteration 4 --
156string(11) "-2147483648"
157-- Iteration 5 --
158string(11) "-2147483647"
159-- Iteration 6 --
160string(10) "2147483647"
161-- Iteration 7 --
162string(10) "2147483640"
163-- Iteration 8 --
164string(4) "4667"
165-- Iteration 9 --
166string(4) "4779"
167-- Iteration 10 --
168string(4) "4095"
169-- Iteration 11 --
170string(3) "250"
171-- Iteration 12 --
172string(11) "-2147483648"
173-- Iteration 13 --
174string(10) "2147483647"
175-- Iteration 14 --
176string(10) "2147483647"
177-- Iteration 15 --
178string(2) "83"
179-- Iteration 16 --
180string(1) "1"
181-- Iteration 17 --
182string(11) "-2147483648"
183-- Iteration 18 --
184string(10) "2147483647"
185-- Iteration 19 --
186string(11) "-2147483649"
187-- Iteration 20 --
188string(10) "2147483648"
189-- Iteration 21 --
190string(11) "-2147483649"
191-- Iteration 22 --
192string(11) "34359738369"
193-- Iteration 23 --
194string(10) "2147483649"
195-- Iteration 24 --
196string(11) "-2147483649"
197-- Iteration 25 --
198string(1) "0"
199-- Iteration 26 --
200string(4) "-0.1"
201-- Iteration 27 --
202string(2) "10"
203-- Iteration 28 --
204string(7) "1050000"
205-- Iteration 29 --
206string(6) "1.0E-5"
207-- Iteration 30 --
208string(7) "5000000"
209-- Iteration 31 --
210string(7) "6.0E-20"
211-- Iteration 32 --
212string(7) "5.0E+42"
213-- Iteration 33 --
214string(7) "3.4E-33"
215-- Iteration 34 --
216string(1) "1"
217-- Iteration 35 --
218string(1) "1"
219-- Iteration 36 --
220string(0) ""
221-- Iteration 37 --
222string(0) ""
223-- Iteration 38 --
224string(0) ""
225-- Iteration 39 --
226string(0) ""
227-- Iteration 40 --
228string(1) " "
229-- Iteration 41 --
230string(1) " "
231-- Iteration 42 --
232string(1) "0"
233-- Iteration 43 --
234string(1) "0"
235-- Iteration 44 --
236string(7) "testing"
237-- Iteration 45 --
238string(5) "0x564"
239-- Iteration 46 --
240string(4) "0123"
241-- Iteration 47 --
242string(4) "new
243"
244-- Iteration 48 --
245string(5) "new\n"
246-- Iteration 49 --
247string(11) "@#$$%^&&*()"
248-- Iteration 50 --
249string(8) "        "
250-- Iteration 51 --
251string(4) "null"
252-- Iteration 52 --
253string(4) "null"
254-- Iteration 53 --
255string(4) "true"
256-- Iteration 54 --
257string(4) "true"
258-- Iteration 55 --
259string(5%d) "This is a multiline heredoc
260string. Numeric = 1232455."
261-- Iteration 56 --
262string(1%d) "12345
2632345"
264-- Iteration 57 --
265string(0) ""
266
267*** Testing strval() with non_scalar values ***
268-- Iteration 1 --
269string(6) "Object"
270-- Iteration 2 --
271string(14) "Resource id #%d"
272-- Iteration 3 --
273string(14) "Resource id #%d"
274-- Iteration 4 --
275
276Warning: Array to string conversion in %s on line %d
277string(5) "Array"
278-- Iteration 5 --
279
280Warning: Array to string conversion in %s on line %d
281string(5) "Array"
282-- Iteration 6 --
283
284Warning: Array to string conversion in %s on line %d
285string(5) "Array"
286-- Iteration 7 --
287
288Warning: Array to string conversion in %s on line %d
289string(5) "Array"
290-- Iteration 8 --
291string(0) ""
292-- Iteration 9 --
293string(0) ""
294-- Iteration 10 --
295string(0) ""
296-- Iteration 11 --
297string(0) ""
298Done
299