New testcases for array_unshift() function

This commit is contained in:
Raghubansh Kumar 2007-10-19 09:19:57 +00:00
parent ecdb967787
commit 8b8d0541c2
11 changed files with 6739 additions and 0 deletions

View File

@ -0,0 +1,88 @@
--TEST--
Test array_unshift() function : basic functionality - array with default keys for 'array' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing array_unshift() by giving array with default keys for $array argument
*/
echo "*** Testing array_unshift() : basic functionality with default key array ***\n";
// Initialise the array
$array = array(1, 2);
// Calling array_unshift() with default argument
$temp_array = $array;
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
var_dump( array_unshift($temp_array, 10) );
// dump the resulting array
var_dump($temp_array);
// Calling array_unshift() with optional arguments
$temp_array = $array;
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
var_dump( array_unshift($temp_array, 222, "hello", 12.33) );
// dump the resulting array
var_dump($temp_array);
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : basic functionality with default key array ***
int(3)
array(3) {
[0]=>
int(10)
[1]=>
int(1)
[2]=>
int(2)
}
int(5)
array(5) {
[0]=>
int(222)
[1]=>
string(5) "hello"
[2]=>
float(12.33)
[3]=>
int(1)
[4]=>
int(2)
}
Done
--UEXPECTF--
*** Testing array_unshift() : basic functionality with default key array ***
int(3)
array(3) {
[0]=>
int(10)
[1]=>
int(1)
[2]=>
int(2)
}
int(5)
array(5) {
[0]=>
int(222)
[1]=>
unicode(5) "hello"
[2]=>
float(12.33)
[3]=>
int(1)
[4]=>
int(2)
}
Done

View File

@ -0,0 +1,48 @@
--TEST--
Test array_unshift() function : error conditions
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
echo "*** Testing array_unshift() : error conditions ***\n";
// Zero arguments
echo "\n-- Testing array_unshift() function with Zero arguments --\n";
var_dump( array_unshift() );
// Testing array_unshift with one less than the expected number of arguments
echo "\n-- Testing array_unshift() function with less than expected no. of arguments --\n";
$array = array(1, 2);
var_dump( array_unshift($array) );
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : error conditions ***
-- Testing array_unshift() function with Zero arguments --
Warning: Wrong parameter count for array_unshift() in %s on line %d
NULL
-- Testing array_unshift() function with less than expected no. of arguments --
Warning: Wrong parameter count for array_unshift() in %s on line %d
NULL
Done
--UEXPECTF--
*** Testing array_unshift() : error conditions ***
-- Testing array_unshift() function with Zero arguments --
Warning: Wrong parameter count for array_unshift() in %s on line %d
NULL
-- Testing array_unshift() function with less than expected no. of arguments --
Warning: Wrong parameter count for array_unshift() in %s on line %d
NULL
Done

View File

@ -0,0 +1,559 @@
--TEST--
Test array_unshift() function : usage variations - unexpected values for 'array' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the behavior of array_unshift() by giving values
* other than array values for $array argument
*/
echo "*** Testing array_unshift() : unexpected values for \$array argument ***\n";
// Initialise $var argument
$var = 12;
// 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");
// get an unset variable
$unset_var = 10;
unset ($unset_var);
// array of unexpected values to be passed to $array argument
$arrays = 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*/ "",
'',
// string data
/*18*/ "string",
'string',
$heredoc,
// object data
/*21*/ new classA(),
// undefined data
@$undefined_var,
// unset data
@$unset_var,
// resource variable
/*24*/ $fp
);
// loop through each element of $arrays to test the functionality of array_unshift()
$iterator = 1;
foreach($arrays as $array) {
echo "\n-- Iteration $iterator --";
/* with default arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var) );
// dump the resulting array
var_dump($temp_array);
/* with optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') );
// dump the resulting array
var_dump($temp_array);
$iterator++;
};
// close the file resource used
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : unexpected values for $array argument ***
-- Iteration 1 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(0)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(0)
-- Iteration 2 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(1)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(1)
-- Iteration 3 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(12345)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(12345)
-- Iteration 4 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(-2345)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(-2345)
-- Iteration 5 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(10.5)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(10.5)
-- Iteration 6 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(-10.5)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(-10.5)
-- Iteration 7 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(123456789000)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(123456789000)
-- Iteration 8 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(1.23456789E-9)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(1.23456789E-9)
-- Iteration 9 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(0.5)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(0.5)
-- Iteration 10 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 11 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 12 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
-- Iteration 13 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
-- Iteration 14 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
-- Iteration 15 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
-- Iteration 16 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(0) ""
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(0) ""
-- Iteration 17 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(0) ""
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(0) ""
-- Iteration 18 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(6) "string"
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(6) "string"
-- Iteration 19 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(6) "string"
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(6) "string"
-- Iteration 20 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(11) "hello world"
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
string(11) "hello world"
-- Iteration 21 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
object(classA)#%d (0) {
}
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
object(classA)#%d (0) {
}
-- Iteration 22 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 23 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 24 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
resource(%d) of type (stream)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
resource(%d) of type (stream)
Done
--UEXPECTF--
*** Testing array_unshift() : unexpected values for $array argument ***
-- Iteration 1 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(0)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(0)
-- Iteration 2 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(1)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(1)
-- Iteration 3 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(12345)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(12345)
-- Iteration 4 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(-2345)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
int(-2345)
-- Iteration 5 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(10.5)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(10.5)
-- Iteration 6 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(-10.5)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(-10.5)
-- Iteration 7 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(123456789000)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(123456789000)
-- Iteration 8 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(1.23456789E-9)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(1.23456789E-9)
-- Iteration 9 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(0.5)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
float(0.5)
-- Iteration 10 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 11 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 12 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
-- Iteration 13 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
-- Iteration 14 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(true)
-- Iteration 15 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
bool(false)
-- Iteration 16 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(0) ""
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(0) ""
-- Iteration 17 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(0) ""
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(0) ""
-- Iteration 18 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(6) "string"
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(6) "string"
-- Iteration 19 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(6) "string"
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(6) "string"
-- Iteration 20 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(11) "hello world"
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
unicode(11) "hello world"
-- Iteration 21 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
object(classA)#%d (0) {
}
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
object(classA)#%d (0) {
}
-- Iteration 22 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 23 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
NULL
-- Iteration 24 --
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
resource(%d) of type (stream)
Warning: array_unshift(): The first argument should be an array in %s on line %d
bool(false)
resource(%d) of type (stream)
Done

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,680 @@
--TEST--
Test array_unshift() function : usage variations - assoc. array with diff. keys for 'array' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_unshift() by passing different
* associative arrays having different possible keys to $array argument.
* The $var argument passed is a fixed value
*/
echo "*** Testing array_unshift() : associative array with different keys ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
//get a resource variable
$fp = fopen(__FILE__, "r");
//get a class
class classA
{
public function __toString(){
return "Class A object";
}
}
// get a heredoc string
$heredoc = <<<EOT
Hello world
EOT;
// initializing $var argument
$var = 10;
// different variations of associative arrays to be passed to $array argument
$arrays = array (
// empty array
/*1*/ array(),
// arrays with integer keys
array(0 => "0"),
array(1 => "1"),
array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
// arrays with float keys
/*5*/ array(2.3333 => "float"),
array(1.2 => "f1", 3.33 => "f2",
4.89999922839999 => "f3",
33333333.333333 => "f4"),
// arrays with string keys
/*7*/ array('\tHello' => 111, 're\td' => "color",
'\v\fworld' => 2.2, 'pen\n' => 33),
array("\tHello" => 111, "re\td" => "color",
"\v\fworld" => 2.2, "pen\n" => 33),
array("hello", $heredoc => "string"), // heredoc
// array with object, unset variable and resource variable
array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
// array with mixed keys
/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
$fp => 'resource', 133 => "int", 444.432 => "float",
@$unset_var => "unset", $heredoc => "heredoc")
);
// loop through the various elements of $arrays to test array_unshift()
$iterator = 1;
foreach($arrays as $array) {
echo "-- Iteration $iterator --\n";
/* with default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var) );
// dump the resulting array
var_dump($temp_array);
/* with optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') );
// dump the resulting array
var_dump($temp_array);
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : associative array with different keys ***
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
-- Iteration 1 --
int(1)
array(1) {
[0]=>
int(10)
}
int(3)
array(3) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
}
-- Iteration 2 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
string(1) "0"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(1) "0"
}
-- Iteration 3 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
string(1) "1"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(1) "1"
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
string(1) "1"
[2]=>
string(1) "2"
[3]=>
string(1) "3"
[4]=>
string(1) "4"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(1) "1"
[4]=>
string(1) "2"
[5]=>
string(1) "3"
[6]=>
string(1) "4"
}
-- Iteration 5 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
string(5) "float"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(5) "float"
}
-- Iteration 6 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
string(2) "f1"
[2]=>
string(2) "f2"
[3]=>
string(2) "f3"
[4]=>
string(2) "f4"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(2) "f1"
[4]=>
string(2) "f2"
[5]=>
string(2) "f3"
[6]=>
string(2) "f4"
}
-- Iteration 7 --
int(5)
array(5) {
[0]=>
int(10)
["\tHello"]=>
int(111)
["re\td"]=>
string(5) "color"
["\v\fworld"]=>
float(2.2)
["pen\n"]=>
int(33)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["\tHello"]=>
int(111)
["re\td"]=>
string(5) "color"
["\v\fworld"]=>
float(2.2)
["pen\n"]=>
int(33)
}
-- Iteration 8 --
int(5)
array(5) {
[0]=>
int(10)
[" Hello"]=>
int(111)
["re d"]=>
string(5) "color"
[" world"]=>
float(2.2)
["pen
"]=>
int(33)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[" Hello"]=>
int(111)
["re d"]=>
string(5) "color"
[" world"]=>
float(2.2)
["pen
"]=>
int(33)
}
-- Iteration 9 --
int(3)
array(3) {
[0]=>
int(10)
[1]=>
string(5) "hello"
["Hello world"]=>
string(6) "string"
}
int(5)
array(5) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(5) "hello"
["Hello world"]=>
string(6) "string"
}
-- Iteration 10 --
int(2)
array(2) {
[0]=>
int(10)
[""]=>
string(5) "hello"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[""]=>
string(5) "hello"
}
-- Iteration 11 --
int(7)
array(7) {
[0]=>
int(10)
["hello"]=>
int(1)
["fruit"]=>
float(2.2)
[1]=>
string(3) "int"
[2]=>
string(5) "float"
[""]=>
string(5) "unset"
["Hello world"]=>
string(7) "heredoc"
}
int(9)
array(9) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["hello"]=>
int(1)
["fruit"]=>
float(2.2)
[3]=>
string(3) "int"
[4]=>
string(5) "float"
[""]=>
string(5) "unset"
["Hello world"]=>
string(7) "heredoc"
}
Done
--UEXPECTF--
*** Testing array_unshift() : associative array with different keys ***
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
-- Iteration 1 --
int(1)
array(1) {
[0]=>
int(10)
}
int(3)
array(3) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
}
-- Iteration 2 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
unicode(1) "0"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(1) "0"
}
-- Iteration 3 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
unicode(1) "1"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(1) "1"
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
unicode(1) "1"
[2]=>
unicode(1) "2"
[3]=>
unicode(1) "3"
[4]=>
unicode(1) "4"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(1) "1"
[4]=>
unicode(1) "2"
[5]=>
unicode(1) "3"
[6]=>
unicode(1) "4"
}
-- Iteration 5 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
unicode(5) "float"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(5) "float"
}
-- Iteration 6 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
unicode(2) "f1"
[2]=>
unicode(2) "f2"
[3]=>
unicode(2) "f3"
[4]=>
unicode(2) "f4"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(2) "f1"
[4]=>
unicode(2) "f2"
[5]=>
unicode(2) "f3"
[6]=>
unicode(2) "f4"
}
-- Iteration 7 --
int(5)
array(5) {
[0]=>
int(10)
[u"\tHello"]=>
int(111)
[u"re\td"]=>
unicode(5) "color"
[u"\v\fworld"]=>
float(2.2)
[u"pen\n"]=>
int(33)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"\tHello"]=>
int(111)
[u"re\td"]=>
unicode(5) "color"
[u"\v\fworld"]=>
float(2.2)
[u"pen\n"]=>
int(33)
}
-- Iteration 8 --
int(5)
array(5) {
[0]=>
int(10)
[u" Hello"]=>
int(111)
[u"re d"]=>
unicode(5) "color"
[u" world"]=>
float(2.2)
[u"pen
"]=>
int(33)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u" Hello"]=>
int(111)
[u"re d"]=>
unicode(5) "color"
[u" world"]=>
float(2.2)
[u"pen
"]=>
int(33)
}
-- Iteration 9 --
int(3)
array(3) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[u"Hello world"]=>
unicode(6) "string"
}
int(5)
array(5) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(5) "hello"
[u"Hello world"]=>
unicode(6) "string"
}
-- Iteration 10 --
int(2)
array(2) {
[0]=>
int(10)
[u""]=>
unicode(5) "hello"
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u""]=>
unicode(5) "hello"
}
-- Iteration 11 --
int(7)
array(7) {
[0]=>
int(10)
[u"hello"]=>
int(1)
[u"fruit"]=>
float(2.2)
[1]=>
unicode(3) "int"
[2]=>
unicode(5) "float"
[u""]=>
unicode(5) "unset"
[u"Hello world"]=>
unicode(7) "heredoc"
}
int(9)
array(9) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"hello"]=>
int(1)
[u"fruit"]=>
float(2.2)
[3]=>
unicode(3) "int"
[4]=>
unicode(5) "float"
[u""]=>
unicode(5) "unset"
[u"Hello world"]=>
unicode(7) "heredoc"
}
Done

View File

@ -0,0 +1,698 @@
--TEST--
Test array_unshift() function : usage variations - assoc. array with diff values for 'array' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_unshift() by passing different
* associative arrays having different possible values to $array argument.
* The $var argument passed is a fixed value
*/
echo "*** Testing array_unshift() : associative array with different values ***\n";
// get an unset variable
$unset_var = 10;
unset ($unset_var);
// get a resource variable
$fp = fopen(__FILE__, "r");
// get a class
class classA
{
public function __toString() {
return "Class A object";
}
}
// get a heredoc string
$heredoc = <<<EOT
Hello world
EOT;
// initializing $var argument
$var = 10;
// different variations of associative arrays to be passed to $array argument
$arrays = array (
// empty array
/*1*/ array(),
// arrays with integer values
array('0' => 0),
array("1" => 1),
array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
// arrays with float values
/*5*/ array("float" => 2.3333),
array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333),
// arrays with string values
/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"),
array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'),
array(1 => "hello", "heredoc" => $heredoc),
// array with object, unset variable and resource variable
array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
// array with mixed values
/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc)
);
// loop through the various elements of $arrays to test array_unshift()
$iterator = 1;
foreach($arrays as $array) {
echo "-- Iteration $iterator --\n";
/* with default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var) );
// dump the resulting array
var_dump($temp_array);
/* with optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') );
// dump the resulting array
var_dump($temp_array);
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : associative array with different values ***
-- Iteration 1 --
int(1)
array(1) {
[0]=>
int(10)
}
int(3)
array(3) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
}
-- Iteration 2 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
int(0)
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
int(0)
}
-- Iteration 3 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
int(1)
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
int(1)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
int(10)
["one"]=>
int(1)
["two"]=>
int(2)
["three"]=>
int(3)
[1]=>
int(4)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["one"]=>
int(1)
["two"]=>
int(2)
["three"]=>
int(3)
[3]=>
int(4)
}
-- Iteration 5 --
int(2)
array(2) {
[0]=>
int(10)
["float"]=>
float(2.3333)
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["float"]=>
float(2.3333)
}
-- Iteration 6 --
int(5)
array(5) {
[0]=>
int(10)
["f1"]=>
float(1.2)
["f2"]=>
float(3.33)
[1]=>
float(4.8999992284)
["f4"]=>
float(33333333.333333)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f1"]=>
float(1.2)
["f2"]=>
float(3.33)
[3]=>
float(4.8999992284)
["f4"]=>
float(33333333.333333)
}
-- Iteration 7 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
string(6) " Hello"
["red"]=>
string(6) "col or"
[2]=>
string(7) " world"
[3]=>
string(4) "pen
"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(6) " Hello"
["red"]=>
string(6) "col or"
[4]=>
string(7) " world"
[5]=>
string(4) "pen
"
}
-- Iteration 8 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
string(7) "\tHello"
["red"]=>
string(7) "col\tor"
[2]=>
string(9) "\v\fworld"
[3]=>
string(5) "pen\n"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(7) "\tHello"
["red"]=>
string(7) "col\tor"
[4]=>
string(9) "\v\fworld"
[5]=>
string(5) "pen\n"
}
-- Iteration 9 --
int(3)
array(3) {
[0]=>
int(10)
[1]=>
string(5) "hello"
["heredoc"]=>
string(11) "Hello world"
}
int(5)
array(5) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(5) "hello"
["heredoc"]=>
string(11) "Hello world"
}
-- Iteration 10 --
int(4)
array(4) {
[0]=>
int(10)
[1]=>
object(classA)#%d (0) {
}
["unset"]=>
NULL
["resource"]=>
resource(%d) of type (stream)
}
int(6)
array(6) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
object(classA)#%d (0) {
}
["unset"]=>
NULL
["resource"]=>
resource(%d) of type (stream)
}
-- Iteration 11 --
int(9)
array(9) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
object(classA)#%d (0) {
}
[3]=>
string(5) "fruit"
["resource"]=>
resource(%d) of type (stream)
["int"]=>
int(133)
["float"]=>
float(444.432)
["unset"]=>
NULL
["heredoc"]=>
string(11) "Hello world"
}
int(11)
array(11) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
string(5) "hello"
[4]=>
object(classA)#%d (0) {
}
[5]=>
string(5) "fruit"
["resource"]=>
resource(%d) of type (stream)
["int"]=>
int(133)
["float"]=>
float(444.432)
["unset"]=>
NULL
["heredoc"]=>
string(11) "Hello world"
}
Done
--UEXPECTF--
*** Testing array_unshift() : associative array with different values ***
-- Iteration 1 --
int(1)
array(1) {
[0]=>
int(10)
}
int(3)
array(3) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
}
-- Iteration 2 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
int(0)
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
int(0)
}
-- Iteration 3 --
int(2)
array(2) {
[0]=>
int(10)
[1]=>
int(1)
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
int(1)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
int(10)
[u"one"]=>
int(1)
[u"two"]=>
int(2)
[u"three"]=>
int(3)
[1]=>
int(4)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"one"]=>
int(1)
[u"two"]=>
int(2)
[u"three"]=>
int(3)
[3]=>
int(4)
}
-- Iteration 5 --
int(2)
array(2) {
[0]=>
int(10)
[u"float"]=>
float(2.3333)
}
int(4)
array(4) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"float"]=>
float(2.3333)
}
-- Iteration 6 --
int(5)
array(5) {
[0]=>
int(10)
[u"f1"]=>
float(1.2)
[u"f2"]=>
float(3.33)
[1]=>
float(4.8999992284)
[u"f4"]=>
float(33333333.333333)
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f1"]=>
float(1.2)
[u"f2"]=>
float(3.33)
[3]=>
float(4.8999992284)
[u"f4"]=>
float(33333333.333333)
}
-- Iteration 7 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
unicode(6) " Hello"
[u"red"]=>
unicode(6) "col or"
[2]=>
unicode(7) " world"
[3]=>
unicode(4) "pen
"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(6) " Hello"
[u"red"]=>
unicode(6) "col or"
[4]=>
unicode(7) " world"
[5]=>
unicode(4) "pen
"
}
-- Iteration 8 --
int(5)
array(5) {
[0]=>
int(10)
[1]=>
unicode(7) "\tHello"
[u"red"]=>
unicode(7) "col\tor"
[2]=>
unicode(9) "\v\fworld"
[3]=>
unicode(5) "pen\n"
}
int(7)
array(7) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(7) "\tHello"
[u"red"]=>
unicode(7) "col\tor"
[4]=>
unicode(9) "\v\fworld"
[5]=>
unicode(5) "pen\n"
}
-- Iteration 9 --
int(3)
array(3) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[u"heredoc"]=>
unicode(11) "Hello world"
}
int(5)
array(5) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(5) "hello"
[u"heredoc"]=>
unicode(11) "Hello world"
}
-- Iteration 10 --
int(4)
array(4) {
[0]=>
int(10)
[1]=>
object(classA)#%d (0) {
}
[u"unset"]=>
NULL
[u"resource"]=>
resource(%d) of type (stream)
}
int(6)
array(6) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
object(classA)#%d (0) {
}
[u"unset"]=>
NULL
[u"resource"]=>
resource(%d) of type (stream)
}
-- Iteration 11 --
int(9)
array(9) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
object(classA)#%d (0) {
}
[3]=>
unicode(5) "fruit"
[u"resource"]=>
resource(%d) of type (stream)
[u"int"]=>
int(133)
[u"float"]=>
float(444.432)
[u"unset"]=>
NULL
[u"heredoc"]=>
unicode(11) "Hello world"
}
int(11)
array(11) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
unicode(5) "hello"
[4]=>
object(classA)#%d (0) {
}
[5]=>
unicode(5) "fruit"
[u"resource"]=>
resource(%d) of type (stream)
[u"int"]=>
int(133)
[u"float"]=>
float(444.432)
[u"unset"]=>
NULL
[u"heredoc"]=>
unicode(11) "Hello world"
}
Done

View File

@ -0,0 +1,317 @@
--TEST--
Test array_unshift() function : usage variations - two dimensional arrays for 'array' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_unshift() by giving two-dimensional
* arrays and also sub-arrays within the two-dimensional array for $array argument.
* The $var argument passed is a fixed value
*/
echo "*** Testing array_unshift() : two dimensional arrays for \$array argument ***\n";
// initializing $var argument
$var = 10;
// two-dimensional array to be passed to $array argument
$two_dimensional_array = array(
// associative array
array('color' => 'red', 'item' => 'pen', 'place' => 'LA'),
// numeric array
array(1, 2, 3, 4, 5),
// combination of numeric and associative arrays
array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball')
);
/* Passing the entire $two_dimensional_array to $array */
/* With default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $two_dimensional_array;
var_dump( array_unshift($temp_array, $var) ); // whole 2-d array
// dumps the resulting array
var_dump($temp_array);
/* With optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $two_dimensional_array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // whole 2-d array
// dumps the resulting array
var_dump($temp_array);
/* Passing the sub-array within the $two_dimensional_array to $array argument */
/* With default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $two_dimensional_array[0];
var_dump( array_unshift($temp_array, $var) ); // sub array
// dumps the resulting array
var_dump($temp_array);
/* With optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $two_dimensional_array[0];
var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // sub array
// dumps the resulting array
var_dump($temp_array);
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : two dimensional arrays for $array argument ***
int(4)
array(4) {
[0]=>
int(10)
[1]=>
array(3) {
["color"]=>
string(3) "red"
["item"]=>
string(3) "pen"
["place"]=>
string(2) "LA"
}
[2]=>
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
[3]=>
array(7) {
["a"]=>
string(5) "green"
[0]=>
string(3) "red"
[1]=>
string(5) "brown"
[2]=>
int(33)
[3]=>
int(88)
[4]=>
string(6) "orange"
["item"]=>
string(4) "ball"
}
}
int(6)
array(6) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
[3]=>
array(3) {
["color"]=>
string(3) "red"
["item"]=>
string(3) "pen"
["place"]=>
string(2) "LA"
}
[4]=>
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
[5]=>
array(7) {
["a"]=>
string(5) "green"
[0]=>
string(3) "red"
[1]=>
string(5) "brown"
[2]=>
int(33)
[3]=>
int(88)
[4]=>
string(6) "orange"
["item"]=>
string(4) "ball"
}
}
int(4)
array(4) {
[0]=>
int(10)
["color"]=>
string(3) "red"
["item"]=>
string(3) "pen"
["place"]=>
string(2) "LA"
}
int(6)
array(6) {
[0]=>
int(10)
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["color"]=>
string(3) "red"
["item"]=>
string(3) "pen"
["place"]=>
string(2) "LA"
}
Done
--UEXPECTF--
*** Testing array_unshift() : two dimensional arrays for $array argument ***
int(4)
array(4) {
[0]=>
int(10)
[1]=>
array(3) {
[u"color"]=>
unicode(3) "red"
[u"item"]=>
unicode(3) "pen"
[u"place"]=>
unicode(2) "LA"
}
[2]=>
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
[3]=>
array(7) {
[u"a"]=>
unicode(5) "green"
[0]=>
unicode(3) "red"
[1]=>
unicode(5) "brown"
[2]=>
int(33)
[3]=>
int(88)
[4]=>
unicode(6) "orange"
[u"item"]=>
unicode(4) "ball"
}
}
int(6)
array(6) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[3]=>
array(3) {
[u"color"]=>
unicode(3) "red"
[u"item"]=>
unicode(3) "pen"
[u"place"]=>
unicode(2) "LA"
}
[4]=>
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
[4]=>
int(5)
}
[5]=>
array(7) {
[u"a"]=>
unicode(5) "green"
[0]=>
unicode(3) "red"
[1]=>
unicode(5) "brown"
[2]=>
int(33)
[3]=>
int(88)
[4]=>
unicode(6) "orange"
[u"item"]=>
unicode(4) "ball"
}
}
int(4)
array(4) {
[0]=>
int(10)
[u"color"]=>
unicode(3) "red"
[u"item"]=>
unicode(3) "pen"
[u"place"]=>
unicode(2) "LA"
}
int(6)
array(6) {
[0]=>
int(10)
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"color"]=>
unicode(3) "red"
[u"item"]=>
unicode(3) "pen"
[u"place"]=>
unicode(2) "LA"
}
Done

View File

@ -0,0 +1,384 @@
--TEST--
Test array_unshift() function : usage variations - double quoted strings for 'var' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_unshift() by passing different
* double quoted strings for $var argument that is prepended to the array
* passed through $array argument
*/
echo "*** Testing array_unshift() : double quoted strings for \$var argument ***\n";
// array to be passed to $array argument
$array = array('f' => "first", "s" => 'second', 1, 2.222);
// different variations of double quoted strings to be passed to $var argument
$vars = array (
"\$ -> This represents the dollar sign. hello dollar!!!",
"\t\r\v The quick brown fo\fx jumped over the lazy dog",
"This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\",
"hello world\\t",
"This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
);
// loop through the various elements of $arrays to test array_unshift()
$iterator = 1;
foreach($vars as $var) {
echo "-- Iteration $iterator --\n";
$temp_array = $array; // assign $array to another temporary $temp_array
/* with default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
var_dump( array_unshift($temp_array, $var) );
// dump the resulting array
var_dump($temp_array);
/* with optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') );
// dump the resulting array
var_dump($temp_array);
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : double quoted strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
[0]=>
string(53) "$ -> This represents the dollar sign. hello dollar!!!"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(53) "$ -> This represents the dollar sign. hello dollar!!!"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
[0]=>
string(49) "
The quick brown fo x jumped over the lazy dog"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(49) "
The quick brown fo x jumped over the lazy dog"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
[0]=>
string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
string(13) "hello world\t"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(13) "hello world\t"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
[0]=>
string(70) "This is a text in bold letters
\s\malong with slashes
: HELLO WORLD "
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(70) "This is a text in bold letters
\s\malong with slashes
: HELLO WORLD "
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
Done
--UEXPECTF--
*** Testing array_unshift() : double quoted strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
[0]=>
unicode(53) "$ -> This represents the dollar sign. hello dollar!!!"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(53) "$ -> This represents the dollar sign. hello dollar!!!"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
[0]=>
unicode(49) "
The quick brown fo x jumped over the lazy dog"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(49) "
The quick brown fo x jumped over the lazy dog"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
[0]=>
unicode(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
unicode(13) "hello world\t"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(13) "hello world\t"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
[0]=>
unicode(70) "This is a text in bold letters
\s\malong with slashes
: HELLO WORLD "
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(70) "This is a text in bold letters
\s\malong with slashes
: HELLO WORLD "
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
Done

View File

@ -0,0 +1,372 @@
--TEST--
Test array_unshift() function : usage variations - single quoted strings for 'var' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_unshift() by passing different
* single quoted strings for $var argument that is prepended to the array
* passed through $array argument
*/
echo "*** Testing array_unshift() : single quoted strings for \$var argument ***\n";
// array to be passed to $array argument
$array = array('f' => "first", "s" => 'second', 1, 2.222);
// different variations of single quoted strings to be passed to $var argument
$vars = array (
'\$ -> This represents the dollar sign. hello dollar!!!',
'\t\r\v The quick brown fo\fx jumped over the lazy dog',
'This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\',
'hello world\\t',
'This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t'
);
// loop through the various elements of $arrays to test array_unshift()
$iterator = 1;
foreach($vars as $var) {
echo "-- Iteration $iterator --\n";
$temp_array = $array; // assign $array to another temporary $temp_array
/* with default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
var_dump( array_unshift($temp_array, $var) );
// dump the resulting array
var_dump($temp_array);
/* with optional arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') );
// dump the resulting array
var_dump($temp_array);
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : single quoted strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
[0]=>
string(54) "\$ -> This represents the dollar sign. hello dollar!!!"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(54) "\$ -> This represents the dollar sign. hello dollar!!!"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
[0]=>
string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
[0]=>
string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
string(13) "hello world\t"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(13) "hello world\t"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
[0]=>
string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
Done
--UEXPECTF--
*** Testing array_unshift() : single quoted strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
[0]=>
unicode(54) "\$ -> This represents the dollar sign. hello dollar!!!"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(54) "\$ -> This represents the dollar sign. hello dollar!!!"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
[0]=>
unicode(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
[0]=>
unicode(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
unicode(13) "hello world\t"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(13) "hello world\t"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
[0]=>
unicode(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
Done

View File

@ -0,0 +1,526 @@
--TEST--
Test array_unshift() function : usage variations - heredoc strings for 'var' argument
--FILE--
<?php
/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...])
* Description: Pushes elements onto the beginning of the array
* Source code: ext/standard/array.c
*/
/*
* Testing the functionality of array_unshift() by passing different
* heredoc strings for $var argument that is prepended to the array
* passed through $array argument
*/
echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n";
// heredoc with empty value
$empty_string = <<<EOT
EOT;
// heredoc with blank line
$blank_line = <<<EOT
EOT;
// heredoc with multiline string
$multiline_string = <<<EOT
hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string
EOT;
// heredoc with diferent whitespaces
$diff_whitespaces = <<<EOT
hello\r world\t
1111\t\t != 2222\v\v
heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
EOT;
// heredoc with numeric values
$numeric_string = <<<EOT
11 < 12. 123 >22
2222 != 1111.\t 0000 = 0000\n
EOT;
// heredoc with quote chars & slash
$quote_char_string = <<<EOT
This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes
EOT;
// array to be passed to $array argument
$array = array('f' => "first", "s" => 'second', 1, 2.222);
// different heredoc strings to be passed to $var argument
$vars = array(
$empty_string,
$blank_line,
$multiline_string,
$diff_whitespaces,
$numeric_string,
$quote_char_string
);
// loop through the various elements of $arrays to test array_unshift()
$iterator = 1;
foreach($vars as $var) {
echo "-- Iteration $iterator --\n";
$temp_array = $array; // assign $array to another temporary $temp_array
/* with default argument */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
var_dump( array_unshift($temp_array, $var) );
// dump the resulting array
var_dump($temp_array);
/* with all possible arguments */
// returns element count in the resulting array after arguments are pushed to
// beginning of the given array
$temp_array = $array;
var_dump( array_unshift($temp_array, $var, "hello", 'world') );
// dump the resulting array
var_dump($temp_array);
$iterator++;
}
echo "Done";
?>
--EXPECTF--
*** Testing array_unshift() : heredoc strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
[0]=>
string(0) ""
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(0) ""
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
[0]=>
string(1) "
"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(1) "
"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
[0]=>
string(86) "hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(86) "hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
string(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
[0]=>
string(44) "11 < 12. 123 >22
2222 != 1111. 0000 = 0000
"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(44) "11 < 12. 123 >22
2222 != 1111. 0000 = 0000
"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 6 --
int(5)
array(5) {
[0]=>
string(123) "This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
string(123) "This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes"
[1]=>
string(5) "hello"
[2]=>
string(5) "world"
["f"]=>
string(5) "first"
["s"]=>
string(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
Done
--UEXPECTF--
*** Testing array_unshift() : heredoc strings for $var argument ***
-- Iteration 1 --
int(5)
array(5) {
[0]=>
unicode(0) ""
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(0) ""
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 2 --
int(5)
array(5) {
[0]=>
unicode(1) "
"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(1) "
"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 3 --
int(5)
array(5) {
[0]=>
unicode(86) "hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(86) "hello world
The big brown fox jumped over;
the lazy dog
This is a double quoted string"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 4 --
int(5)
array(5) {
[0]=>
unicode(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(88) "hello
world
1111 != 2222
heredoc
double quoted string. with different white spaces"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 5 --
int(5)
array(5) {
[0]=>
unicode(44) "11 < 12. 123 >22
2222 != 1111. 0000 = 0000
"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(44) "11 < 12. 123 >22
2222 != 1111. 0000 = 0000
"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
-- Iteration 6 --
int(5)
array(5) {
[0]=>
unicode(123) "This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[1]=>
int(1)
[2]=>
float(2.222)
}
int(7)
array(7) {
[0]=>
unicode(123) "This's a string with quotes:
"strings in double quote";
'strings in single quote';
this\line is single quoted /with\slashes"
[1]=>
unicode(5) "hello"
[2]=>
unicode(5) "world"
[u"f"]=>
unicode(5) "first"
[u"s"]=>
unicode(6) "second"
[3]=>
int(1)
[4]=>
float(2.222)
}
Done