2 Test array_slice() function : usage variations - Pass different data types as $offset arg
4 <?php if (PHP_INT_SIZE > 4) die("skip this test is for 32bit platform only"); ?>
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
13 * Pass different data types as $offset argument to array_slice() to test behaviour
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
28 public function __toString() {
29 return "Class A object";
38 // get a resource variable
39 $fp = fopen(__FILE__, "r");
41 // unexpected values to be passed to $offset argument
78 /*22*/ @$undefined_var,
84 // loop through each element of $inputs to check the behavior of array_slice()
86 foreach($inputs as $input) {
87 echo "\n-- Iteration $iterator --\n";
88 var_dump( array_slice($input_array, $input) );
98 *** Testing array_slice() : usage variations ***
260 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
265 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
270 Warning: array_slice() expects parameter 2 to be long, array given in %s on line %d
275 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
280 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
285 Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d