--- /dev/null
+--TEST--
+Test array_slice() function : basic functionality
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test basic functionality of array_slice()
+ */
+
+echo "*** Testing array_slice() : basic functionality ***\n";
+
+
+$input = array('one' => 1, 'two' => 2, 3, 23 => 4);
+$offset = 2;
+$length = 2;
+$preserve_keys = true;
+
+// Calling array_slice() with all possible arguments
+echo "\n-- All arguments --\n";
+var_dump( array_slice($input, $offset, $length, $preserve_keys) );
+
+// Calling array_slice() with mandatory arguments
+echo "\n-- Mandatory arguments --\n";
+var_dump( array_slice($input, $offset) );
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : basic functionality ***
+
+-- All arguments --
+array(2) {
+ [0]=>
+ int(3)
+ [23]=>
+ int(4)
+}
+
+-- Mandatory arguments --
+array(2) {
+ [0]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : error conditions - Pass incorrect number of args
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to array_slice() to test behaviour
+ */
+
+echo "*** Testing array_slice() : error conditions ***\n";
+
+//Test array_slice with one more than the expected number of arguments
+echo "\n-- Testing array_slice() function with more than expected no. of arguments --\n";
+$input = array(1, 2);
+$offset = 10;
+$length = 10;
+$preserve_keys = true;
+$extra_arg = 10;
+var_dump( array_slice($input, $offset, $length, $preserve_keys, $extra_arg) );
+
+// Testing array_slice with one less than the expected number of arguments
+echo "\n-- Testing array_slice() function with less than expected no. of arguments --\n";
+var_dump( array_slice($input) );
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing array_slice() : error conditions ***
+
+-- Testing array_slice() function with more than expected no. of arguments --
+
+Warning: array_slice() expects at most 4 parameters, 5 given in %s on line %d
+NULL
+
+-- Testing array_slice() function with less than expected no. of arguments --
+
+Warning: array_slice() expects at least 2 parameters, 1 given in %s on line %d
+NULL
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - Pass different data types as $input arg
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different arguments as $input argument to array_slice() to test behaviour
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$offset = 2;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $input argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+
+ // resource variable
+/*25*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of array_slice()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( array_slice($input, $offset) );
+ $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d
+NULL
+
+-- Iteration 2 --
+
+Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d
+NULL
+
+-- Iteration 3 --
+
+Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d
+NULL
+
+-- Iteration 4 --
+
+Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d
+NULL
+
+-- Iteration 5 --
+
+Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d
+NULL
+
+-- Iteration 6 --
+
+Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d
+NULL
+
+-- Iteration 7 --
+
+Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d
+NULL
+
+-- Iteration 8 --
+
+Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d
+NULL
+
+-- Iteration 9 --
+
+Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d
+NULL
+
+-- Iteration 10 --
+
+Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 11 --
+
+Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 12 --
+
+Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d
+NULL
+
+-- Iteration 13 --
+
+Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d
+NULL
+
+-- Iteration 14 --
+
+Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d
+NULL
+
+-- Iteration 15 --
+
+Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d
+NULL
+
+-- Iteration 16 --
+
+Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d
+NULL
+
+-- Iteration 18 --
+array(0) {
+}
+
+-- Iteration 19 --
+
+Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d
+NULL
+
+-- Iteration 22 --
+
+Warning: array_slice() expects parameter 1 to be array, object given in %s on line %d
+NULL
+
+-- Iteration 23 --
+
+Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 24 --
+
+Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d
+NULL
+
+-- Iteration 25 --
+
+Warning: array_slice() expects parameter 1 to be array, resource given in %s on line %d
+NULL
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - position of internal array pointer
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Check position of internal array pointer after calling array_slice()
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+$input = array ('one' => 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero');
+
+echo "\n-- Call array_slice() --\n";
+var_dump($result = array_slice($input, 2));
+
+echo "-- Position of Internal Pointer in Result: --\n";
+echo key($result) . " => " . current($result) . "\n";
+echo "\n-- Position of Internal Pointer in Original Array: --\n";
+echo key($input) . " => " . current ($input) . "\n";
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Call array_slice() --
+array(2) {
+ [0]=>
+ string(12) "twenty-three"
+ [1]=>
+ string(4) "zero"
+}
+-- Position of Internal Pointer in Result: --
+0 => twenty-three
+
+-- Position of Internal Pointer in Original Array: --
+one => un
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - Pass different data types as $offset arg
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different data types as $offset argument to array_slice() to test behaviour
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$input_array = array('one' => 1, 2, 'three' => 3, 4);
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $offset argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // undefined data
+/*22*/ @$undefined_var,
+
+ // unset data
+/*23*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of array_slice()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( array_slice($input_array, $input) );
+ $iterator++;
+};
+
+fclose($fp);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Iteration 1 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 2 --
+array(3) {
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 3 --
+array(0) {
+}
+
+-- Iteration 4 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 5 --
+array(0) {
+}
+
+-- Iteration 6 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 7 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 8 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 9 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 10 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 11 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 12 --
+array(3) {
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 13 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 14 --
+array(3) {
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 15 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 16 --
+
+Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 17 --
+
+Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 18 --
+
+Warning: array_slice() expects parameter 2 to be long, array given in %s on line %d
+NULL
+
+-- Iteration 19 --
+
+Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 20 --
+
+Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 21 --
+
+Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d
+NULL
+
+-- Iteration 22 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+
+-- Iteration 23 --
+array(4) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ ["three"]=>
+ int(3)
+ [1]=>
+ int(4)
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - Pass different data types as $length arg
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different data types as $length argument to array_slice to test behaviour
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$input_array = array('one' => 1, 2, 'three' => 3, 4);
+$offset = 2;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $length argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // undefined data
+/*22*/ @$undefined_var,
+
+ // unset data
+/*23*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of array_slice
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( array_slice($input_array, $offset, $input) );
+ $iterator++;
+};
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Iteration 1 --
+array(0) {
+}
+
+-- Iteration 2 --
+array(1) {
+ ["three"]=>
+ int(3)
+}
+
+-- Iteration 3 --
+array(2) {
+ ["three"]=>
+ int(3)
+ [0]=>
+ int(4)
+}
+
+-- Iteration 4 --
+array(0) {
+}
+
+-- Iteration 5 --
+array(2) {
+ ["three"]=>
+ int(3)
+ [0]=>
+ int(4)
+}
+
+-- Iteration 6 --
+array(0) {
+}
+
+-- Iteration 7 --
+array(0) {
+}
+
+-- Iteration 8 --
+array(0) {
+}
+
+-- Iteration 9 --
+array(0) {
+}
+
+-- Iteration 10 --
+array(2) {
+ ["three"]=>
+ int(3)
+ [0]=>
+ int(4)
+}
+
+-- Iteration 11 --
+array(2) {
+ ["three"]=>
+ int(3)
+ [0]=>
+ int(4)
+}
+
+-- Iteration 12 --
+array(1) {
+ ["three"]=>
+ int(3)
+}
+
+-- Iteration 13 --
+array(0) {
+}
+
+-- Iteration 14 --
+array(1) {
+ ["three"]=>
+ int(3)
+}
+
+-- Iteration 15 --
+array(0) {
+}
+
+-- Iteration 16 --
+array(0) {
+}
+
+-- Iteration 17 --
+array(0) {
+}
+
+-- Iteration 18 --
+array(0) {
+}
+
+-- Iteration 19 --
+array(0) {
+}
+
+-- Iteration 20 --
+array(0) {
+}
+
+-- Iteration 21 --
+array(0) {
+}
+
+-- Iteration 22 --
+array(2) {
+ ["three"]=>
+ int(3)
+ [0]=>
+ int(4)
+}
+
+-- Iteration 23 --
+array(2) {
+ ["three"]=>
+ int(3)
+ [0]=>
+ int(4)
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - Pass different data types as $preserve_keys arg
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different data types as $preserve_keys argument to array_slice() to test behaviour
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$input_array = array('one' => 1, 2, 99 => 3, 4);
+$offset = 0;
+$length = 3;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+ public function __toString() {
+ return "Class A object";
+ }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// unexpected values to be passed to $preserve_keys argument
+$inputs = array(
+
+ // int data
+/*1*/ 0,
+ 1,
+ 12345,
+ -2345,
+
+ // float data
+/*5*/ 10.5,
+ -10.5,
+ 12.3456789000e10,
+ 12.3456789000E-10,
+ .5,
+
+ // null data
+/*10*/ NULL,
+ null,
+
+ // boolean data
+/*12*/ true,
+ false,
+ TRUE,
+ FALSE,
+
+ // empty data
+/*16*/ "",
+ '',
+ array(),
+
+ // string data
+/*19*/ "string",
+ 'string',
+ $heredoc,
+
+ // object data
+/*22*/ new classA(),
+
+ // undefined data
+/*23*/ @$undefined_var,
+
+ // unset data
+/*24*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of array_slice()
+$iterator = 1;
+foreach($inputs as $input) {
+ echo "\n-- Iteration $iterator --\n";
+ var_dump( array_slice($input_array, $offset, $length, $input) );
+ $iterator++;
+};
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Iteration 1 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 2 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 3 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 4 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 5 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 6 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 7 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 8 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 9 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 10 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 11 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 12 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 13 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 14 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 15 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 16 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 17 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 18 --
+
+Warning: array_slice() expects parameter 4 to be boolean, array given in %s on line %d
+NULL
+
+-- Iteration 19 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 20 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 21 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [99]=>
+ int(3)
+}
+
+-- Iteration 22 --
+
+Warning: array_slice() expects parameter 4 to be boolean, object given in %s on line %d
+NULL
+
+-- Iteration 23 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+
+-- Iteration 24 --
+array(3) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - Pass different integers as $offset argument
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different integers as $offset argument to test how array_slice() behaves
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10);
+
+for ($i = -7; $i <= 7; $i++) {
+ echo "\n-- \$offset is $i --\n";
+ var_dump(array_slice($input, $i));
+}
+echo "\n-- \$offset is maximum integer value --\n";
+var_dump(array_slice($input, PHP_INT_MAX));
+
+echo "\n-- \$offset is minimum integer value --\n";
+var_dump(array_slice($input, -PHP_INT_MAX));
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- $offset is -7 --
+array(5) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is -6 --
+array(5) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is -5 --
+array(5) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is -4 --
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is -3 --
+array(3) {
+ [0]=>
+ string(5) "three"
+ [1]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is -2 --
+array(2) {
+ [0]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is -1 --
+array(1) {
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is 0 --
+array(5) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is 1 --
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is 2 --
+array(3) {
+ [0]=>
+ string(5) "three"
+ [1]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is 3 --
+array(2) {
+ [0]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is 4 --
+array(1) {
+ ["ten"]=>
+ int(10)
+}
+
+-- $offset is 5 --
+array(0) {
+}
+
+-- $offset is 6 --
+array(0) {
+}
+
+-- $offset is 7 --
+array(0) {
+}
+
+-- $offset is maximum integer value --
+array(0) {
+}
+
+-- $offset is minimum integer value --
+array(5) {
+ ["one"]=>
+ int(1)
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - pass different int values as $length arg
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different integer values as $length argument to array_slice() to test behaviour
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10);
+$offset = 1;
+
+for ($i = -6; $i <= 6; $i++) {
+ echo "\n-- \$length is $i --\n";
+ var_dump(array_slice($input, $offset, $i));
+}
+echo "\n-- \$length is maximum integer value --\n";
+var_dump(array_slice($input, $offset, PHP_INT_MAX));
+
+echo "\n-- \$length is minimum integer value --\n";
+var_dump(array_slice($input, $offset, -PHP_INT_MAX));
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- $length is -6 --
+array(0) {
+}
+
+-- $length is -5 --
+array(0) {
+}
+
+-- $length is -4 --
+array(0) {
+}
+
+-- $length is -3 --
+array(1) {
+ [0]=>
+ string(3) "two"
+}
+
+-- $length is -2 --
+array(2) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+}
+
+-- $length is -1 --
+array(3) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+}
+
+-- $length is 0 --
+array(0) {
+}
+
+-- $length is 1 --
+array(1) {
+ [0]=>
+ string(3) "two"
+}
+
+-- $length is 2 --
+array(2) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+}
+
+-- $length is 3 --
+array(3) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+}
+
+-- $length is 4 --
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $length is 5 --
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $length is 6 --
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $length is maximum integer value --
+array(4) {
+ [0]=>
+ string(3) "two"
+ [1]=>
+ string(5) "three"
+ [2]=>
+ string(4) "nine"
+ ["ten"]=>
+ int(10)
+}
+
+-- $length is minimum integer value --
+array(0) {
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - different data types as keys in an array
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Pass different data types as keys in an array to array_slice()
+ * to test how $preserve_keys treats them
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$offset = 0;
+$length = 10; // to ensure all elements are displayed
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// arrays of different data types to be passed as $input
+$inputs = array(
+
+ // int data
+/*1*/ 'int' => array(
+ 0 => 'zero',
+ 1 => 'one',
+ 12345 => 'positive',
+ -2345 => 'negative',
+ ),
+
+ // float data
+/*2*/ 'float' => array(
+ 10.5 => 'positive',
+ -10.5 => 'negative',
+ .5 => 'half',
+ ),
+
+/*3*/ 'extreme floats' => array(
+ 12.3456789000e6 => 'large',
+ 12.3456789000E-10 => 'small',
+ ),
+
+ // null data
+/*4*/ 'null uppercase' => array(
+ NULL => 'null 1',
+ ),
+
+/*5*/ 'null lowercase' => array(
+ null => 'null 2',
+ ),
+
+ // boolean data
+/*6*/ 'bool lowercase' => array(
+ true => 'lowert',
+ false => 'lowerf',
+ ),
+
+/*7*/ 'bool uppercase' => array(
+ TRUE => 'uppert',
+ FALSE => 'upperf',
+ ),
+
+ // empty data
+/*8*/ 'empty double quotes' => array(
+ "" => 'emptyd',
+ ),
+
+/*9*/ 'empty single quotes' => array(
+ '' => 'emptys',
+ ),
+
+ // string data
+/*10*/ 'string' => array(
+ "stringd" => 'stringd',
+ 'strings' => 'strings',
+ $heredoc => 'stringh',
+ ),
+
+ // undefined data
+/*11*/ 'undefined' => array(
+ @$undefined_var => 'undefined',
+ ),
+
+ // unset data
+/*12*/ 'unset' => array(
+ @$unset_var => 'unset',
+ ),
+);
+
+// loop through each element of $inputs to check the behavior of array_slice()
+$iterator = 1;
+foreach($inputs as $type => $input) {
+ echo "\n-- Iteration $iterator : key type is $type --\n";
+ echo "\$preserve_keys = TRUE\n";
+ var_dump( array_slice($input, $offset, $length, true) );
+ echo "\$preserve_keys = FALSE\n";
+ var_dump( array_slice($input, $offset, $length, false) );
+ $iterator++;
+};
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Iteration 1 : key type is int --
+$preserve_keys = TRUE
+array(4) {
+ [0]=>
+ string(4) "zero"
+ [1]=>
+ string(3) "one"
+ [12345]=>
+ string(8) "positive"
+ [-2345]=>
+ string(8) "negative"
+}
+$preserve_keys = FALSE
+array(4) {
+ [0]=>
+ string(4) "zero"
+ [1]=>
+ string(3) "one"
+ [2]=>
+ string(8) "positive"
+ [3]=>
+ string(8) "negative"
+}
+
+-- Iteration 2 : key type is float --
+$preserve_keys = TRUE
+array(3) {
+ [10]=>
+ string(8) "positive"
+ [-10]=>
+ string(8) "negative"
+ [0]=>
+ string(4) "half"
+}
+$preserve_keys = FALSE
+array(3) {
+ [0]=>
+ string(8) "positive"
+ [1]=>
+ string(8) "negative"
+ [2]=>
+ string(4) "half"
+}
+
+-- Iteration 3 : key type is extreme floats --
+$preserve_keys = TRUE
+array(2) {
+ [12345678]=>
+ string(5) "large"
+ [0]=>
+ string(5) "small"
+}
+$preserve_keys = FALSE
+array(2) {
+ [0]=>
+ string(5) "large"
+ [1]=>
+ string(5) "small"
+}
+
+-- Iteration 4 : key type is null uppercase --
+$preserve_keys = TRUE
+array(1) {
+ [""]=>
+ string(6) "null 1"
+}
+$preserve_keys = FALSE
+array(1) {
+ [""]=>
+ string(6) "null 1"
+}
+
+-- Iteration 5 : key type is null lowercase --
+$preserve_keys = TRUE
+array(1) {
+ [""]=>
+ string(6) "null 2"
+}
+$preserve_keys = FALSE
+array(1) {
+ [""]=>
+ string(6) "null 2"
+}
+
+-- Iteration 6 : key type is bool lowercase --
+$preserve_keys = TRUE
+array(2) {
+ [1]=>
+ string(6) "lowert"
+ [0]=>
+ string(6) "lowerf"
+}
+$preserve_keys = FALSE
+array(2) {
+ [0]=>
+ string(6) "lowert"
+ [1]=>
+ string(6) "lowerf"
+}
+
+-- Iteration 7 : key type is bool uppercase --
+$preserve_keys = TRUE
+array(2) {
+ [1]=>
+ string(6) "uppert"
+ [0]=>
+ string(6) "upperf"
+}
+$preserve_keys = FALSE
+array(2) {
+ [0]=>
+ string(6) "uppert"
+ [1]=>
+ string(6) "upperf"
+}
+
+-- Iteration 8 : key type is empty double quotes --
+$preserve_keys = TRUE
+array(1) {
+ [""]=>
+ string(6) "emptyd"
+}
+$preserve_keys = FALSE
+array(1) {
+ [""]=>
+ string(6) "emptyd"
+}
+
+-- Iteration 9 : key type is empty single quotes --
+$preserve_keys = TRUE
+array(1) {
+ [""]=>
+ string(6) "emptys"
+}
+$preserve_keys = FALSE
+array(1) {
+ [""]=>
+ string(6) "emptys"
+}
+
+-- Iteration 10 : key type is string --
+$preserve_keys = TRUE
+array(3) {
+ ["stringd"]=>
+ string(7) "stringd"
+ ["strings"]=>
+ string(7) "strings"
+ ["hello world"]=>
+ string(7) "stringh"
+}
+$preserve_keys = FALSE
+array(3) {
+ ["stringd"]=>
+ string(7) "stringd"
+ ["strings"]=>
+ string(7) "strings"
+ ["hello world"]=>
+ string(7) "stringh"
+}
+
+-- Iteration 11 : key type is undefined --
+$preserve_keys = TRUE
+array(1) {
+ [""]=>
+ string(9) "undefined"
+}
+$preserve_keys = FALSE
+array(1) {
+ [""]=>
+ string(9) "undefined"
+}
+
+-- Iteration 12 : key type is unset --
+$preserve_keys = TRUE
+array(1) {
+ [""]=>
+ string(5) "unset"
+}
+$preserve_keys = FALSE
+array(1) {
+ [""]=>
+ string(5) "unset"
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - multidimensional arrays
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_slice when passed
+ * 1. a two-dimensional array as $input argument
+ * 2. a sub-array as $input argument
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+$input = array ('zero', 'one', array('zero', 'un', 'deux'), 9 => 'nine');
+
+echo "\n-- Slice a two-dimensional array --\n";
+var_dump(array_slice($input, 1, 3));
+
+echo "\n-- \$input is a sub-array --\n";
+var_dump(array_slice($input[2], 1, 2));
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Slice a two-dimensional array --
+array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "zero"
+ [1]=>
+ string(2) "un"
+ [2]=>
+ string(4) "deux"
+ }
+ [2]=>
+ string(4) "nine"
+}
+
+-- $input is a sub-array --
+array(2) {
+ [0]=>
+ string(2) "un"
+ [1]=>
+ string(4) "deux"
+}
+Done
\ No newline at end of file
--- /dev/null
+--TEST--
+Test array_slice() function : usage variations - referenced variables
+--FILE--
+<?php
+/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]])
+ * Description: Returns elements specified by offset and length
+ * Source code: ext/standard/array.c
+ */
+
+/*
+ * Test array_slice() when:
+ * 1. Passed an array of referenced variables
+ * 2. $input argument is passed by reference
+ */
+
+echo "*** Testing array_slice() : usage variations ***\n";
+
+$val1 = 'one';
+$val2 = 'two';
+$val3 = 'three';
+
+echo "\n-- Array of referenced variables (\$preserve_keys = default) --\n";
+$input = array(3 => &$val1, 2 => &$val2, 1 => &$val3);
+var_dump(array_slice($input, 1, 2));
+
+echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n";
+$val2 = 'hello, world';
+var_dump(array_slice($input, 1, 2, true));
+
+echo "\n-- Pass array by reference --\n";
+$new_input = array (1, 2, 3);
+var_dump(array_slice(&$new_input, 1));
+echo "-- Check passed array: --\n";
+var_dump($new_input);
+
+echo "Done";
+?>
+
+--EXPECTF--
+*** Testing array_slice() : usage variations ***
+
+-- Array of referenced variables ($preserve_keys = default) --
+array(2) {
+ [0]=>
+ &string(3) "two"
+ [1]=>
+ &string(5) "three"
+}
+-- Change $val2 ($preserve_keys = TRUE) --
+array(2) {
+ [2]=>
+ &string(12) "hello, world"
+ [1]=>
+ &string(5) "three"
+}
+
+-- Pass array by reference --
+array(2) {
+ [0]=>
+ int(2)
+ [1]=>
+ int(3)
+}
+-- Check passed array: --
+array(3) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+}
+Done
\ No newline at end of file