Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / php / ext / standard / tests / array / array_slice_variation2.phpt
blob217788fec7b17904040b1d8b0010d9fa44917d27
1 --TEST--
2 Test array_slice() function : usage variations - Pass different data types as $offset arg
3 --SKIPIF--
4 <?php if (PHP_INT_SIZE > 4) die("skip this test is for 32bit platform only"); ?>
5 --FILE--
6 <?php
7 /* Prototype  : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
8  * Description: Returns elements specified by offset and length 
9  * Source code: ext/standard/array.c
10  */
13  * Pass different data types as $offset argument to array_slice() to test behaviour
14  */
16 echo "*** Testing array_slice() : usage variations ***\n";
18 // Initialise function arguments not being substituted
19 $input_array = array('one' => 1, 2, 'three' => 3, 4);
21 //get an unset variable
22 $unset_var = 10;
23 unset ($unset_var);
25 // get a class
26 class classA
28   public function __toString() {
29     return "Class A object";
30   }
33 // heredoc string
34 $heredoc = <<<EOT
35 hello world
36 EOT;
38 // get a resource variable
39 $fp = fopen(__FILE__, "r");
41 // unexpected values to be passed to $offset argument
42 $inputs = array(
44        // int data
45 /*1*/  0,
46        1,
47        12345,
48        -2345,
50        // float data
51 /*5*/  10.5,
52        -10.5,
53        12.3456789000e10,
54        12.3456789000E-10,
55        .5,
57        // null data
58 /*10*/ NULL,
59        null,
61        // boolean data
62 /*12*/ true,
63        false,
64        TRUE,
65        FALSE,
66        
67        // empty data
68 /*16*/ "",
69        '',
70        array(),
72        // string data
73 /*19*/ "string",
74        'string',
75        $heredoc,
77        // undefined data
78 /*22*/ @$undefined_var,
80        // unset data
81 /*23*/ @$unset_var,
84 // loop through each element of $inputs to check the behavior of array_slice()
85 $iterator = 1;
86 foreach($inputs as $input) {
87   echo "\n-- Iteration $iterator --\n";
88   var_dump( array_slice($input_array, $input) );
89   $iterator++;
92 fclose($fp);
94 echo "Done";
97 --EXPECTF--
98 *** Testing array_slice() : usage variations ***
100 -- Iteration 1 --
101 array(4) {
102   ["one"]=>
103   int(1)
104   [0]=>
105   int(2)
106   ["three"]=>
107   int(3)
108   [1]=>
109   int(4)
112 -- Iteration 2 --
113 array(3) {
114   [0]=>
115   int(2)
116   ["three"]=>
117   int(3)
118   [1]=>
119   int(4)
122 -- Iteration 3 --
123 array(0) {
126 -- Iteration 4 --
127 array(4) {
128   ["one"]=>
129   int(1)
130   [0]=>
131   int(2)
132   ["three"]=>
133   int(3)
134   [1]=>
135   int(4)
138 -- Iteration 5 --
139 array(0) {
142 -- Iteration 6 --
143 array(4) {
144   ["one"]=>
145   int(1)
146   [0]=>
147   int(2)
148   ["three"]=>
149   int(3)
150   [1]=>
151   int(4)
154 -- Iteration 7 --
155 array(4) {
156   ["one"]=>
157   int(1)
158   [0]=>
159   int(2)
160   ["three"]=>
161   int(3)
162   [1]=>
163   int(4)
166 -- Iteration 8 --
167 array(4) {
168   ["one"]=>
169   int(1)
170   [0]=>
171   int(2)
172   ["three"]=>
173   int(3)
174   [1]=>
175   int(4)
178 -- Iteration 9 --
179 array(4) {
180   ["one"]=>
181   int(1)
182   [0]=>
183   int(2)
184   ["three"]=>
185   int(3)
186   [1]=>
187   int(4)
190 -- Iteration 10 --
191 array(4) {
192   ["one"]=>
193   int(1)
194   [0]=>
195   int(2)
196   ["three"]=>
197   int(3)
198   [1]=>
199   int(4)
202 -- Iteration 11 --
203 array(4) {
204   ["one"]=>
205   int(1)
206   [0]=>
207   int(2)
208   ["three"]=>
209   int(3)
210   [1]=>
211   int(4)
214 -- Iteration 12 --
215 array(3) {
216   [0]=>
217   int(2)
218   ["three"]=>
219   int(3)
220   [1]=>
221   int(4)
224 -- Iteration 13 --
225 array(4) {
226   ["one"]=>
227   int(1)
228   [0]=>
229   int(2)
230   ["three"]=>
231   int(3)
232   [1]=>
233   int(4)
236 -- Iteration 14 --
237 array(3) {
238   [0]=>
239   int(2)
240   ["three"]=>
241   int(3)
242   [1]=>
243   int(4)
246 -- Iteration 15 --
247 array(4) {
248   ["one"]=>
249   int(1)
250   [0]=>
251   int(2)
252   ["three"]=>
253   int(3)
254   [1]=>
255   int(4)
258 -- Iteration 16 --
260 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
261 NULL
263 -- Iteration 17 --
265 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
266 NULL
268 -- Iteration 18 --
270 Warning: array_slice() expects parameter 2 to be long, array given in %s on line %d
271 NULL
273 -- Iteration 19 --
275 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
276 NULL
278 -- Iteration 20 --
280 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
281 NULL
283 -- Iteration 21 --
285 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
286 NULL
288 -- Iteration 22 --
289 array(4) {
290   ["one"]=>
291   int(1)
292   [0]=>
293   int(2)
294   ["three"]=>
295   int(3)
296   [1]=>
297   int(4)
300 -- Iteration 23 --
301 array(4) {
302   ["one"]=>
303   int(1)
304   [0]=>
305   int(2)
306   ["three"]=>
307   int(3)
308   [1]=>
309   int(4)
311 Done